MySQL Forums
Forum List  »  PHP

Newbie Q i'm sure =\...
Posted by: Jayyde
Date: February 10, 2006 06:30PM

Just started all this not too long ago (read a day ago ;) ). Can someone tell me why the below code doesn't read the if ($id) code properly? The url in the browser changes and is sending it, but everytime it still displays the list of accounts (the else) instead of the detail for the account that it's passing the id of...

===============================

<?php
$db = mysql_connect("localhost", "root",) or die ("Unable to connect to MySQL Server");
mysql_select_db("finances",$db);
$count = 0;

if ($id)
{
$result = mysql_query("SELECT * FROM tblaccount WHERE iAccountId=$id",$db);
$myrow = mysql_fetch_array($result);

printf("ID: %s\n<br>", $myrow["iAccountId"]);
printf("Type ID: %s\n<br>", $myrow["iAccountTypeId"]);
printf("Name: %s\n<br>", $myrow["sAccountName"]);
printf("Balance: %s\n<br>", $myrow["decAccountBalance"]);
}
else
{
// show account list
$result = mysql_query("SELECT * FROM tblaccount",$db);
if ($myrow = mysql_fetch_array($result))
{
// display list if there are records to display
do
{
printf("<a href=\"%s?id=%s\">%s</a><br>\n", $PHP_SELF, $myrow["iAccountId"], $myrow["sAccountName"]);
++$count;
} while ($myrow = mysql_fetch_array($result));
}

// How many results were returned
print ("<br><br>".$count." records were found!");
}
?>

Options: ReplyQuote


Subject
Written By
Posted
Newbie Q i'm sure =\...
February 10, 2006 06:30PM
February 10, 2006 11:48PM
February 11, 2006 08:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.