Jump to content

A Dropdown box with multiple columns? Populated from SQL


grahamb314

Recommended Posts

Hi ,

 

I have a drop down box which displays show names from an SQL query (Below)

I want to further this and allow it to display the shows field and the genre field from the database

 

Any help at all would be fantastic!

 

//index.php

 

<html>

<head>

<title></title>

</head>

<body>

 

<p align="center"><strong><img src="Purple_Logo.jpg" width="300" height="113" /></strong>

<p align="center"><strong>Delete a Show

  </strong>

  </div>

<form action="delete_show_results.php" method="POST">

 

  <div align="center">

    <p>

      <select name="toDelete">

     

<?php

require_once 'mysql_connect.php'; 

$DJshows = mysqli_query($mysqli, "SELECT * FROM shows");

while ($show = mysqli_fetch_assoc($DJshows)) { 

echo "<option value=\"{$show['show']}\">{$show['show']}</option>";

}

?>

      </select>

    </p>

    <p>

      <input type="submit" value="Delete"></p>

     

  </div>

</form>

 

</form>

   

 

<div align="center">

  <input name="BUTTON3" type="BUTTON" onClick="javascript:history.go(-1)" value="Back">

</div>

</body>

</html>

Link to comment
Share on other sites

to this line, just add the genre field

 

echo "<option value=\"{$show['show']}\">{$show['show']}</option>";

 

echo "<option value=\"{$show['show']}\">{$show['show']}  {$show['genre']}</option>";

 

That will put the genre in the dropdown menu. if that is what you are talking about.

Link to comment
Share on other sites

<?php
$query = "SELECT * FROM table ";
$result = mysql_query($query) or die ("<b class='red'>There is nothing on record</b>".mysql_error());
//... process contents of $result ...

// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=1 border=1 bgcolor='lightblue'>";
?>

<TR>
<TH>header1</TH>
<TH>header2</TH>
</TR>

<?php
while($row = mysql_fetch_row($result)) {
?>

<TR>
<TD WIDTH="90"><a href=test.php><?php echo $row[0]; ?></a></TD>
<TD WIDTH="90"><a href=test.php><?php echo $row[1]; ?></a></TD>
</TR>

<?php
}
?>

<?php	
}
echo "</table>";
}
?>

 

This will get a table and link what it outputs to test.php

Link to comment
Share on other sites

Yes that is correct, I have it going to test.php, you will have to change it to whatever page you want it to go to.

 

EDIT

 

You will not use post, you will use $_GET

 

Links will look like this<a href=test.php?id=<?php echo $show['show']; ?>

 

and on the next page, you will do

 

$show = $_GET['id'];

 

and do you sql queries from there.

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.