corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » php & mysql question


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author php & mysql question
Antz
Member

Registered: 28th Jul 03
Location: Leeds         Drives: Myself Insane!
User status: Offline
30th Jan 04 at 23:05   View User's Profile U2U Member Reply With Quote

I know, I know, I know... this is a car forum... I'm sorry, I have looked tons of places and need an ansrew lol....

Below is a sample of my code... can anyone tell me why it only displays 1 result when it clearly has SELECT * FROM tblmain?????

Cheers.

<?php require_once('../Connections/AddressBook.php'); ?>
<?php
mysql_select_db($database_AddressBook, $AddressBook);
$query_All = "SELECT * FROM tblmain";
$All = mysql_query($query_All, $AddressBook) or die(mysql_error());
$row_All = mysql_fetch_assoc($All);
$totalRows_All = mysql_num_rows($All);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Address Book</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php
echo("<TABLE border=\"1\" bordercolor=\"black\" bgcolor=\"red\"><TR bgcolor=\"lightblue\"><TD>Name</TD><TD>Address</TD><TD>Telephone</TD><TD>Fax</TD><TD>E-Mail Address</TD></TR>");
echo("<TR bgcolor=\"white\"><TD>".$row_All["Name"]."</TD><TD>".$row_All["Address"]."</TD><TD>".$row_All["Telephone"]."</TD><TD>".$row_All["Fax"]."</TD><TD>".$row_All["email"]."</TD></TR>");
echo("</TABLE>");
?>

</body>
</html>
<?php
mysql_free_result($All);
?>
Dom
Member

Registered: 13th Sep 03
User status: Offline
30th Jan 04 at 23:26   View User's Profile U2U Member Reply With Quote

you have to do a loop through all of the database records to get them out mate
I dont programe in php, but its along the lines of -

code:

Do While NOT rs.eof

'your display code here

Loop



also mate, put the main table stuff outside the php and just leave the <TR> and <TD> tag is the loop display code
Antz
Member

Registered: 28th Jul 03
Location: Leeds         Drives: Myself Insane!
User status: Offline
30th Jan 04 at 23:31   View User's Profile U2U Member Reply With Quote

Cheers for that, I did take the table tags out soon after posting lol... I work with php all day long but the pages are all done so I never really need to write new queries, just copy and paste lol.
Dom
Member

Registered: 13th Sep 03
User status: Offline
30th Jan 04 at 23:43   View User's Profile U2U Member Reply With Quote

oh, forgot to add abit, before the end of the loop, put rs.MoveNext, this selects the next database record to get
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
1st Feb 04 at 00:16   View Garage View User's Profile U2U Member Reply With Quote

Fill a string with the SQL statement
Execute
While the result {
do stuff
}

If you don't get sorted let me know and I've got code here.
Antz
Member

Registered: 28th Jul 03
Location: Leeds         Drives: Myself Insane!
User status: Offline
1st Feb 04 at 13:02   View User's Profile U2U Member Reply With Quote

Nice one, cheers Ian
Antz
Member

Registered: 28th Jul 03
Location: Leeds         Drives: Myself Insane!
User status: Offline
20th Feb 04 at 22:24   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Ian
Fill a string with the SQL statement
Execute
While the result {
do stuff
}

If you don't get sorted let me know and I've got code here.


Hey dude, tried all sorts, still can't sort it you think it's cos dreamweaver is crap or you think I am?? lol... could you let me sample some of your code please?

Cheers.

[Edited on 20-02-2004 by Ant D]
daimj69
Member

Registered: 20th Jan 01
Location: UK
User status: Offline
20th Feb 04 at 22:33   View User's Profile U2U Member Reply With Quote

This is the sort of thing i've used.

$conn = mysql_connect("localhost","","");
mysql_select_db("mysitedb");
$res = mysql_query("SELECT * FROM members", $conn);

if(mysql_num_rows($res)<1)
{
echo "<B>No Records!</B>";
}
else
{
while($row = mysql_fetch_array($res))
{
$username = $row['username'];
echo $username;
}


Hope it's of some help.

Bye,
Dai.

[Edited on 20-02-2004 by daimj69]

[Edited on 20-02-2004 by daimj69]

[Edited on 20-02-2004 by daimj69]
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
20th Feb 04 at 23:38   View Garage View User's Profile U2U Member Reply With Quote

Ant - get a completely bog standard while loop working, exactly the same as Dai has posted about but tailor the table and field names to your own data.
ed
Member

Registered: 10th Sep 03
User status: Offline
21st Feb 04 at 00:09   View User's Profile U2U Member Reply With Quote

Erm... May not be very helpful, but if you get Dreamweaver it does it all for you...
Laney
Member

Registered: 6th May 03
Location: Leeds
User status: Offline
21st Feb 04 at 00:23   View User's Profile U2U Member Reply With Quote

http://www.devshed.com - The alternative to Dreamweaver
GLSi GUY
Member

Registered: 5th May 02
Location: Preston, Lancs
User status: Offline
21st Feb 04 at 00:28   View User's Profile U2U Member Reply With Quote

nerds

 
New Topic

New Poll

Corsa Sport » Message Board » Off Day » php & mysql question 23 database queries in 0.0087991 seconds