Jump to content

trying to list users events by user id getting this error..


mattsolomon

Recommended Posts

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/largemus/public_html/assets/inc/upcoming.php on line 15

 

i have hidden connection details for this example

 

<?php
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE user = $session->clientid ORDER BY date ASC LIMIT 3;";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>


<div style="width:385px;">

<table style="width: 385px; text-align:center;">
	<tr>
		<td style="width: 121px"><h3>Client</h3></td>
		<td style="width: 100px"><h3>Occasion</h3></td>
		<td style="width: 80px"><h3>Location</h3></td>
		<td><h3>Date</h3></td>
	</tr>
</table>

<table style="width: 385px">
	<tr>
		<td style="width: 121px">
			<p><? echo $rows['clientid']; ?></p>
		</td>
		<td style="width: 100px">
			<p><? echo $rows['occasion']; ?></p>
		</td>
		<td style="width: 80px">
			<p><? echo $rows['location']; ?></p>
		</td>
		<td>
			<p><? echo $rows['date']; ?></p>
		</td>
	</tr>
</table>

</div>

<?
}
mysql_close(); //close database
?>

 

You need to use single quotes around the user like this..

 

$sql="SELECT * FROM $tbl_name WHERE user = '".$session->clientid."' ORDER BY date ASC LIMIT 3;";

 

This MAY work too..

$sql="SELECT * FROM $tbl_name WHERE user = '$session->clientid' ORDER BY date ASC LIMIT 3;";

 

If not then this

$sql="SELECT * FROM $tbl_name WHERE user = '{$session->clientid}' ORDER BY date ASC LIMIT 3;";

thanks, one more thing, when it repeats the 3 events it also copies the first table of "client" "occasion" "location" "date" how can i make it just copy the table with the data in it? insted of copying the tittle table?

 

(if that makes sense)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.