-
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
-
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++;
}
-
You are not still using that horrible tutorial are you??
-
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?
-
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.
-
hmm.. thats cool thanks, i might look into sessions though, are these a tough thing to learn?
-
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']}");
?>