Jump to content

[SOLVED] php mysql lookup/display page


aaronk99

Recommended Posts

Hello All!

I'm a newbe here, but hope to be a regular patron in the next few month/years...

 

I'm having a bit of a problem that I am sure has a simple solution but after spending a day trying to figure it out I figured I would head to the "Tree of Knowledge" so to speak.

 

Here is my situation:

 

I'm trying to create a class lookup page with php/mysql. It has one table with three fields:

 

    TABLE NAME = classes

        Field 01 = id

        Field 02 = class

        Field 03 = info

 

I'm trying to make a page, that when a class is selected, a page will open to display the info for that class. I finaly figured out how to create a drop down menu populated by the class field, but I can't seem to figure out what steps I need to create that display page. I NEED HELLLLPPPPPP...

 

Here is the code I have at this point:

<?php

include 'db.php';

$query="SELECT class,id FROM classes";


$result = mysql_query ($query);
echo "<select name=class value=''>Class</option>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[class]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 

?>

 

If someone could just point me in the right direction I would be very thankfull.

 

Let me know if I need to add any additional info.

Thanks

Aaron

Link to comment
Share on other sites

 

<?php

 

include 'db.php';

 

 

 

$result = mysql_query("SELECT * FROM classes");

echo "<select name="class">";

// printing the list box select command

 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt

echo "<option value=\"viewclass.php?id=".$nt['id']."\">$nt['class']</option>";

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

 

?>

 

 

 

now when they click the class, they will be sent to viewclass.php

 

viewclass.php

<?php
$classid = $_GET['id'];

if(isset($classid)) {
$query = mysql_query("SELECT * FROM classes WHERE id='$classid'");

while($nt = mysql_fetch_array($query) {
echo $nt['class']."<br />".$nt['info'];
}

}
?>

Link to comment
Share on other sites

Alrighty... First off THANK YOU MikeDXUNL for your help. I tweeked the code, added a submit button, created the view page. Everything was going smoothly...

 

but....  >:( The results page is empty, it's not showing anything. Did I miss something in the code? I did check the names of the table fields and they are right. and I made sure the info field had info.

 

I have it running on my server if anyone wants to see the results: http://reception.cre8tive.cc/test02.php

 

Here is the test02.php code:

<?php

include 'db.php';



$result = mysql_query("SELECT * FROM classes");
echo "<select name='class'>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=\"viewclass.php?id=".$nt['id']."\">$nt[class]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 

?>

<html>
<form action="viewclass.php" method="POST">
  <div align="left">
  <input type="submit" value="Go!">
  </div>
</form>
</html>

 

Here is the viewclass.php code:

<?php
$classid = $_GET['id'];

if(isset($classid)) {
$query = mysql_query("SELECT * FROM classes WHERE id='$classid'");

while($nt = mysql_fetch_array($query)) {
echo $nt['class']."<br />".$nt['info'];
}

}
?>

 

I'm wondering if I need to add an html table for the results to display in. Could that be the cause of nothing displaying?

 

Thanks again from anyone who may be able to help.

Link to comment
Share on other sites

try this:

 

test02.php

<html>
<body>
<form action="viewclass.php" method="GET">

<?php

include 'db.php';



$result = mysql_query("SELECT * FROM classes");
echo "<select name=\"id\">";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=\"".$nt['id']."\">$nt['class']</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 

?>


  <div align="left">
  <input type="submit" value="Go!">
  </div>
</form>
</body>
</html>

 

 

 

i just tested it on my localhost and it works....

 

i changed the form method to GET and go rid of the URL in the option value... and replaced it with just the id

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.