PDA

Click to See Complete Forum and Search --> : mysql error


Pino
Nov 3rd, 2004, 01:24 PM
$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

Pino
Nov 3rd, 2004, 01:31 PM
never mind fixed it :)


$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++;
}

visualAd
Nov 3rd, 2004, 02:05 PM
You are not still using that horrible tutorial are you??

Pino
Nov 3rd, 2004, 02:08 PM
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



$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?

visualAd
Nov 3rd, 2004, 02:26 PM
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:

$location="display.php?r=$result&n=$num";

header("Location: $location");

You don't need dots if your embedding variables in your string.

Pino
Nov 3rd, 2004, 02:28 PM
hmm.. thats cool thanks, i might look into sessions though, are these a tough thing to learn?

visualAd
Nov 3rd, 2004, 03:50 PM
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
session_start();

$_SESSION['username'] = $_POST['username'];
?>
<a href="page2.php?<?php echo(SID) ?>">Next Page</a>


page2.php

<?php
session_start();

echo("Hello {$_SESSION['username']}");
?>