Hi all,

I have a database with contact info, and I need to display the info in groups. Currently in my database table called contacts I have a field called 'groups'. The values are 'favorites', 'home', 'work', and 'friends'.

I tried creating a page called group.php and used a dropdown box to select the group, and as per the value in the dropdown box, the affected rows from the SQL database should appear. However I'm presented with a error:

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

And here is my code from groups.php.

include ("dbConfig.php");
require ("check.php");
 <div align ="center">
 Welcome  <?php $_SESSION["valid_user"] ?> Not you? <a href=http://localhost/cas/logout.php\">Click here.</a>
 <br />
 <table align="center" width="1100" border="0">
 <td width="1000"><div align='center'><h1> Contacts</h1></div></td>
 <td width="100">Select a group: <form action="groups.php" method="post"><select name = "chooser">
 					<option value='all'>All</option>
					<option value='favorites'>Favorites</option>
  					<option value='home'>Home</option>
  					<option value='work'>Work</option>
  					<option value='friends'>Friends</option>
						 </select><input type="submit" value="Select" name="select"></form></td>
 <table align="center" width="1100" border="0">
 <td width="100"><b>Name</b></td>
 <td width="200"><b>Email</b></td>
 <td width="100"><b>Age</b></td>
 <td width="100"><b>Birthday</b></td>
 <td width="400"><b>Address</b></td>
 <td width="270"><b>Number</b></td>
//delete check

if(isset ($_GET['id2']))
	$id2 = $_GET['id2'];
	// --------- here code to connect to mysql and select database -----------

	$query= mysql_query("delete FROM contacts where id2 = $id2")or die(mysql_error());


//store the current user into a variable
$username  = $_SESSION["valid_user"];
$group     = $_POST['chooser'];

//select table
$result = mysql_query("SELECT id2, name, email, age, birthday, address, number, uploadedfile FROM contacts WHERE username='$username' AND group='$group'");

//grab content
   $self = $_SERVER['PHP_SELF'];
  //display the row
  echo "<table align=\"center\" width=\"1100\" border=\"0\">";
//  echo "<tr>";
//  echo "<td width=\"200\"><b>Name</b></td>";
//  echo "<td width=\"250\"><b>Email</b></td>";
//  echo "<td width=\"100\"><b>Age</b></td>";
//  echo "<td width=\"100\"><b>Birthday</b></td>";
//  echo "<td width=\"400\"><b>Address</b></td>";
//  echo "<td width=\"200\"><b>Handphone Number</b></td>";
//  echo "<td><b>Photo</b></td>";
//  echo "</tr>";   
  echo "<tr>";
  echo "<td width=\"100\">$name <a href=\"edit.php?cmd=edit&id2=$id2\">(Edit)</a> | <a href = \"$self?id2=$id2\">(Delete)</a></td>";
  echo "<td width=\"200\">$email</td>";
  echo "<td width=\"100\">$age</td>";
  echo "<td width=\"100\">$birthday</td>";
  echo "<td width=\"400\">$address</td>";
  echo "<td width=\"200\">$number</td>";
  echo "<td><img src=\"http://localhost/cas/uploads/$r[uploadedfile]\"alt=\"\" name=\"\" width=\"100\" height=\"110\" border=\"1\"/></img></td>";
  echo "</tr>";
  echo "</table>";
  echo "<br />";
  echo "<br />";
  echo "<br />";
  echo "<div align =\"center\">";
  echo "<a href=\"http://localhost/cas/members.php\">Member Home</a>";
  echo "</div>";


Please help. Any help would be much appreciated, and this is very urgent. Thank you.

Damn, got it. Shouldn't have used 'groups' as a column name. Why is it always minutes after I solved a problem I get to solve it myself?

Be a part of the DaniWeb community

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