|
-
Nov 3rd, 2004, 02:24 PM
#1
Thread Starter
PowerPoster
mysql error
PHP Code:
$query="SELECT * FROM clients WHERE username='$username'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while($i < $num)
{
$msg=mysql_result($result,$i,"msg");
echo $msg;
++$i
}
anyone see any problems? i am connected to the DB
-
Nov 3rd, 2004, 02:31 PM
#2
Thread Starter
PowerPoster
never mind fixed it 
PHP Code:
$query="SELECT * FROM clients WHERE username='$username'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$cur=0;
while($num > $cur)
{
$row=mysql_fetch_array($result);
$themsg = $row["adminmsg"];
echo $themsg;
$cur++;
}
-
Nov 3rd, 2004, 03:05 PM
#3
You are not still using that horrible tutorial are you??
-
Nov 3rd, 2004, 03:08 PM
#4
Thread Starter
PowerPoster
thought not but i printed both guides out and they kind of got mixed up, i found the right one in the end,
while i'm here
ok i'm trying to pass a few varibles to another page
PHP Code:
$location="\display.php?r=.'$result'.&n=.'$num'."
header("Location: $location");
i will then use the get method to extract these varibles from the url,
is this the bets way to d it? if so how would i fix it? if not what is the best way to go about it?
-
Nov 3rd, 2004, 03:26 PM
#5
Using the query string is but one way of passing varaibles between pages. You can also use cookies an sessions. Using the query string is the safest methods with regards to compatibility, becuase you don't have to worry about whether or not the client supports cookies.
To pass the variable $result:
PHP Code:
$location="display.php?r=$result&n=$num";
header("Location: $location");
You don't need dots if your embedding variables in your string.
-
Nov 3rd, 2004, 03:28 PM
#6
Thread Starter
PowerPoster
hmm.. thats cool thanks, i might look into sessions though, are these a tough thing to learn?
-
Nov 3rd, 2004, 04:50 PM
#7
The idea behind sessions in PHP is that they encapsulate the persistance of data through a PHP application. All you need to do is start the sessions with session_start() and put variables into the $_SESSION superglobal array. PHP does the rest.
If the client supports cookies then it will use a cookie to identify the client. If they do not then you can append the identification to the quwery string of URLS.
http://uk.php.net/manual/en/ref.session.php
I have an example of how to use sessions in my signature. But here is an even shorter example:
page1.php
PHP Code:
<?php
session_start();
$_SESSION['username'] = $_POST['username'];
?>
<a href="page2.php?<?php echo(SID) ?>">Next Page</a>
page2.php
PHP Code:
<?php
session_start();
echo("Hello {$_SESSION['username']}");
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|