Antz
Member
Registered: 28th Jul 03
Location: Leeds Drives: Myself Insane!
User status: Offline
|
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
|
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
|
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
|
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
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
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
|
Nice one, cheers Ian
|
Antz
Member
Registered: 28th Jul 03
Location: Leeds Drives: Myself Insane!
User status: Offline
|
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
|
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
Registered: 28th Aug 99
Location: Liverpool
User status: Online
|
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
|
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
|
http://www.devshed.com - The alternative to Dreamweaver
|
GLSi GUY
Member
Registered: 5th May 02
Location: Preston, Lancs
User status: Offline
|
nerds
|