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>

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.

Thats perfect thanks (and so simple!)

 

One last thing. Doing that doesnt look very good, any suggestions to make lit look more presentable? - I mean by putting column headings in etc? - Or a better idea? - Your the expert!

<?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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.