Jump to content

Retrieving the passed ID


vindesigns

Recommended Posts

Hi,

 

I wonder if you guys could help me. I have a table called modules and within it it has moduleID, moduleTitle, moduleCode etc.

 

A checkbox is populated next to each module that is displayed and the value of the checkbox is the moduleID. When a user checks the modules and click submit they get passed onto another page. On this other page I have managed to retrieve the moduleID's which have been checked but I am having trouble in turning these moduleID so that I can display the moduleTitle, moduleCode etc for the ones that have been checked on this new page.

 

I have used the following code but no luck  :confused:

 

  <?php

$cats_upload = "";
foreach($_POST['module'] as $cats) // errors if no modules are selected
{
  echo '<p>Module data moduleID: '.$cats.'</p>';

}
	$sql = mysql_query("SELECT * FROM modules WHERE moduleID ='".$cats."'");


$productCount = mysql_num_rows($sql); //count the output amount

if($productCount > 0){
while($row = mysql_fetch_array($sql)){	

$moduleTitle = $row["moduleTitle"];


	$cats_upload .= "<tr><td>$moduleTitle</td></tr>"; 

}
} else { 
$cats_upload = "<tr><td>No modules have been selected</td></tr>";
}

?>

 

 

 

If anyone has any suggestions to what it might be, please let me know.

Thanks

Link to comment
Share on other sites

This could not work .. your $cats is defined only inside the foreach loop

 

 

<?php

$cats_upload = "";
$cats_sql_match_string
foreach($_POST['module'] as $cats) // errors if no modules are selected
{
  echo '<p>Module data moduleID: '.$cats.'</p>';
 $cats_sql_match_string.=$cats.",";

}
 $cats_sql_match_string=substr($cats_sql_match_string, 0,strlen($cats_sql_match_string)-1);
// the mysql extension to PHP is full of problems, you might want to switch to mysqli
// you might also want to centralize all your queries into one function query($stuff) in order to avoid maintenance nightmares (as in switching from a db extension to another)
	$sql = mysql_query("SELECT * FROM modules WHERE moduleID IN'".$cats_sql_match_string."'");

// Besides, executing a query with potentially no $cats at all is not a good idea, add some checks for that
$productCount = mysql_num_rows($sql); //count the output amount

if($productCount > 0){
while($row = mysql_fetch_array($sql)){	

Link to comment
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.