hello all, I am looking for some help doing multiple queries.
I have two tables that are not related that I need to query on on PHP page.
The page is for people to register for an event.
The first table has a selection of dates for people to arrive and depart from an event (for registration purposes). The second table is a table containing the users information(name, address, etc) that they registered with.

On the page, I would like to have their information already populated, to verify, and then the form for registering, and drop boxes to display the registration dates.

The query on the table for the event dates is below

$result = mysql_query("SELECT DATE_FORMAT(firstarrival, '%d %M %Y') as newfirsta, DATE_FORMAT(secondarrival, '%d %M %Y') as newseconda, DATE_FORMAT(firstdepart, '%d %M %Y') as newfirstd, DATE_FORMAT(seconddepart, '%d %M %Y') as newsecondd FROM events WHERE eventID = ".$eventid."");
if (!$result){
	exit('<p>Could not retrieve the data because: <b>'. mysql_error() . "</b>. The query was $event.</p>");
}
$traveldates = array();

while ($row = mysql_fetch_assoc($result)) {
	$traveldates[] = array (
		"newfirsta" 		=> $row["newfirsta"],
		"newseconda"		=> $row["newseconda"],
		"newfirstd"			=> $row["newfirstd"],
		"newsecondd"		=> $row["newsecondd"]
		);
}

and that works fine. if I try to call the variable, it works.

This is the code that comes right after this for doing the query on the user table (it's pulling a user ID from a cookie)

$query = "SELECT * FROM participants WHERE participantID = '.$participantid.'";
if (!$query){
	exit('<p>Could not retrieve the data because: <b>'. mysql_error() . "</b>. The query was $query.</p>");
}
$row = mysql_fetch_assoc($query);
$participants					=array();
$participants["prefix"]			= $row["prefix"];
$participants["firstname"]		= $row["firstname"];
$participants["middleinitial"]	= $row["middleinitial"];
$participants["lastname"]		= $row["lastname"];

This displays no data when calling the variable i.e.($participants) displays nothing.

Any help would be greatly appreciated.

"SELECT * FROM participants WHERE participantID = '.$participantid.'";

remove the periods between '.$participantid.'

Thanks.. I have tried that with no luck. I have posted the entire code below. Mind you, this is just trying to get everything working, so the HTML code after the PHP is simply for testing. Once I get it working, I'll finish the rest.

Thanks for your help.

$connection = @mysql_connect($db_server, $db_user, $db_password);
if (!$connection) {
	exit("<p>Could not connect!</p><pre>".mysql_error()."</pre>");
}

$select = @mysql_select_db($db_name);
if (!$select) {
	exit("<p>Could not select database!</p><pre>".mysql_error()."</pre>");	
}

$eventid=mysql_real_escape_string($_GET["id"], $connection);
$participantid = $_COOKIE["userid"];

$result = mysql_query("SELECT DATE_FORMAT(firstarrival, '%d %M %Y') as newfirsta, DATE_FORMAT(secondarrival, '%d %M %Y') as newseconda, DATE_FORMAT(firstdepart, '%d %M %Y') as newfirstd, DATE_FORMAT(seconddepart, '%d %M %Y') as newsecondd FROM events WHERE eventID = ".$eventid."");
if (!$result){
	exit('<p>Could not retrieve the data because: <b>'. mysql_error() . "</b>. The query was $event.</p>");
}
$traveldates = array();

while ($row = mysql_fetch_assoc($result)) {
	$traveldates[] = array (
		"newfirsta" 		=> $row["newfirsta"],
		"newseconda"		=> $row["newseconda"],
		"newfirstd"			=> $row["newfirstd"],
		"newsecondd"		=> $row["newsecondd"]
		);
}

$query = "SELECT * FROM participants WHERE participantID = ".$participantid."";
if (!$query){
	exit('<p>Could not retrieve the data because: <b>'. mysql_error() . "</b>. The query was $query.</p>");
}

$row1 = mysql_fetch_assoc($query);
$participants					=array();
$participants["prefix"]			= $row1["prefix"];
$participants["firstname"]		= $row1["firstname"];
$participants["middleinitial"]	= $row1["middleinitial"];
$participants["lastname"]		= $row1["lastname"];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
Event ID: <?php echo $eventid?>
<br />
Participant ID: <?php echo $participantid?>
<br />
First Name: <?php echo ($participants["lastname"]) ?>
<br />
<?php foreach($traveldates as $traveldate) {?>
Travel Date: <?php echo htmlentities ($traveldate["newfirsta"])?> <br />
Travel Date: <?php echo htmlentities ($traveldate["newseconda"])?><br />
Travel Date: <?php echo htmlentities ($traveldate["newfirstd"])?><br />
Travel Date: <?php echo htmlentities ($traveldate["newsecondd"])?>	
<?php } ?>
</body>
</html>

haha, I can't believe I didn't notice. you forgot mysql_query around your the string.

$query = mysql_query("SELECT * FROM participants WHERE participantID = $participantid");
$result = mysql_query("SELECT DATE_FORMAT(firstarrival, '%d %M %Y') as newfirsta,...

is different than:

$query = "SELECT * FROM participants WHERE participantID = ".$participantid."";

I do not see the mysql call in the second. Typically, if you set up $query, then follow it when:

$result = mysql_query($query, $connection);

I hope it is that easy. Good luck.

Thanks, that worked out perfectly. It needed the $connection string and the mysql query

Thanks.

Thanks, that worked out perfectly. It needed the $connection string and the mysql query

Thanks.

Actually you don't need $connection unless you have multiple mysql connections open. If you leave it out it will just use the most recently opened connection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.