Jump to content

Recommended Posts

Hi, I am trying to echo the first and last name of a set of people in a table. I keep gettin the error:

 

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Inetpub\wwwroot\padgate2\TMPmyn02xogw6.php on line 57

 

and before that it only echoed the first person in the table.

 

The 'userhall' table has the columns 'id' and 'hallid'

The 'hall' table has 'hallid' and 'name'

 

<?php
mysql_connect("localhost", "admin", "admin") or die("Cannot connect to DB!");

mysql_select_db("padgate") or die("Cannot select DB!");

$hall_name = $_GET['hall'];

$hallid = "SELECT hallid FROM hall WHERE name = '$hall_name'";

$hi = mysql_query($hallid) or die(mysql_error()."<Br /><br /.".$hallid); // don't use your SQL statement in your error. 

$rowh = mysql_fetch_array($hi);
$hallid2 = $rowh['hallid'];

$hall = "SELECT id FROM userhall WHERE hallid = '$hallid2'";

$h = mysql_query($hall) or die(mysql_error()."<Br /><br /.".$hall); // don't use your SQL statement in your error. 


?>

 

<?php

if (mysql_num_rows($h) == 0) {
echo 'Apparently no one lives in ' $hall_name ' hall!' ;
} else {
echo 'The following people live in ' $hall_name ' Hall! </p>';
while($rowa = mysql_fetch_array($h)) {
	$userid = $rowa['id'];
	$hallmembers = "SELECT * FROM user WHERE id = '$userid'";
	$m = mysql_query($hallmembers) or die(mysql_error()."<Br /><br /.".$hallmembers); // don't use your SQL statement in your error. It will let malicious users know your table structure and open it up to sql injection.
	$row = mysql_fetch_array($m);
	{
echo '<a href ="userprofile.php?user=';
echo $row['id'];
echo '">';
echo $row['f_name'];
echo ' ';
echo $row['l_name'],"</a><br />\n";

}

}
?>code]

Any help to get this working would be great!

Thanks,

Gareth

Link to comment
https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.