Jump to content

Select from a menu a listing from a database?


phpuserlogin

Recommended Posts

<?php

# Set page title and display header section.
$page_title = 'database' ;
include ( 'includes/header.html' ) ;

# Open database connection.
require ( 'connect_db.php' ) ;


$q = "SELECT * FROM forum" ;
$r = mysqli_query( $dbc, $q ) ;
if ( mysqli_num_rows( $r ) > 0 )
{
  echo '<table><tr><th>Posted By</th><th>Subject</th><th id="msg">Message</th></tr>';
  while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
  {
    echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td>
    <td>' . $row['subject'] . '</td><td>' . $row['message'] . '</td> </tr>';
  }
  echo '</table>' ;
}
else { echo '<p>There are currently no messages.</p>' ; }

# Close database connection.
mysqli_close( $dbc ) ;
  
# Display footer section.
include ( 'includes/footer.html' ) ;

?>

I would like to select one row list of the following. As this old example displays a bunch of rows, so a drop down menu would individual select one item from the sql. Can I do that with this example, is it complicated to do so?

 

 

displayfromdatabase.jpg

Link to comment
Share on other sites

  • 4 weeks later...
$q = "SELECT * FROM forum" ;
$r = mysqli_query( $dbc, $q ) ;
if ( mysqli_num_rows( $r ) > 0 )
{
  echo '<table><tr><th>Posted By</th><th>Subject</th><th id="msg">Message</th></tr>';
  while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
  {
    echo '<tr><td>' . $row['first_name'] .' '. $row['last_name'] . '<br>'. $row['post_date'].'</td>
    <td>' . $row['subject'] . '</td><td>' . $row['message'] . '</td> </tr>';
  }
  echo '</table>' ;
}

So row Posted by, do I make a link in order to select that column, or use a drop down. to select a specific row for the data. Posted by is just an example. Record data 1, a very basic example is just what I'm trying to tinker with, with this code. Subject and so on.

Edited by phpuserlogin
Link to comment
Share on other sites

<?php

# Set page title and display header section.
$page_title = 'database' ;
include ( 'includes/header.html' ) ;

# Open database connection.
require ( 'connect_db.php' ) ;

# Display body section, retrieving from 'forum' database table.
$q = "SELECT * FROM forum" ;
$r = mysqli_query( $dbc, $q ) ;
if ( mysqli_num_rows( $r ) > 0 )
{
  echo '<table><tr><th>Posted By</th><th>Subject</th>';
  while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
  {
    echo '<tr><td>
    <td>' . $row['subject'] . '</td><td>' . '</td> </tr>';
  }
  echo '</table>' ;
}
else { echo '<p>There are currently no messages.</p>' ; }

# Close database connection.
mysqli_close( $dbc ) ;
  
# Display footer section.
include ( 'includes/footer.html' ) ;

?>

 

displayfromeditsql.jpg

Link to comment
Share on other sites

  • 1 month later...
<?php

# Set page title and display header section.
$page_title = 'database' ;
include ( 'includes/header.html' ) ;

# Open database connection.
require ( 'connect_db.php' ) ;

# Display body section, retrieving from 'forum' database table.
$q = "SELECT * FROM forum" ;
$r = mysqli_query( $dbc, $q ) ;
if ( mysqli_num_rows( $r ) > 0 )
{
  echo '<table>';
  while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
  {
    echo '
    <td>' . $row['subject'] . '</td> </tr>';
  }
  echo '</table>' ;
}
else { echo '<p>There are currently no messages.</p>' ; }

# Close database connection.
mysqli_close( $dbc ) ;
  
# Display footer section.
include ( 'includes/footer.html' ) ;

?>

I've updated it, so it just displays the words in the subject row from the sql.

So Playstation 2 model no would be selected from the actual subject row, via link, and a drop down menu would be the select method.

I've solved the display of the data.

How do I create a link to select subject row or what ever.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...