Help - Search - Members - Calendar
Full Version: Need Help In Php
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
rahul_puri20
Hi,

I need some help. i have a page with a list box containing id. when i choose a id i have to show the info belongs to the id in the same page. the info are in the database with the id. I m using php and javascript

I think u understand the prob, if not, inform me.

Thanks
Stalkie
Hi

You can try something like this. Now remember this is only a quick sketch to get you on the right track.

CODE
<html-code-design>

<?
// Connect to the database
mysql_connect('server', 'username', 'password');
mysql_select_db('database');

// Only when the form is submitted and id is number only
if ($_SERVER['REQUEST_METHOD'] == 'POST' && preg_match('^[0-9]+$', $_POST['infoID'])
{   $result = mysql_query('SELECT infoTitle, infoText FROM infos WHERE infoID=$_POST['infoID'] LIMIT 1');
    if (mysql_num_rows($result) > 0)
    {   $row = mysql_fetch_assoc($result);
         echo '<b>'.$row['infoTitle'].'</b><br />';
         echo $row['infoText'];
     }
     else
     {    echo 'Unknown ID';
     }
}
?>
<form name="infoForm" action="" method="post">
<select name="infoID" size="1">
  <?
  $result = mysql_query('SELECT infoID, infoTitle FROM infos ORDER BY infoTitle');
  while ($row = mysql_fetch_assoc($result))
  {   echo '<option value="'.$row['infoID'].'">'.$row['infoTitle'].'</option>';
  }
  ?>
</select>
</form>

<?
// Closes the database
mysql_close();
?>


I hope i've understood it correctly
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.