Jump to content

List Db Contents


Crew-Portal

Recommended Posts

Hi long time since my last post! anyways can someone help me make a script that will list the information in one colum in my table! See each clan I have has an ID, and CEO and bla bla bla! But what I want done is it to only show the name of the clan in A dropdown menu. So that when users are signing up they can select the clan they want and it well ya you know puts the name beside theres in the table. But can someone make me a script to list all the clans Names and only names not ID, Ceos, and all that other stuff. Just the name of the clan.. in an

<select name="select">

<option>

Clan names!  

</option>

</select>

type of format?! Thanks In Advance!

Link to comment
https://forums.phpfreaks.com/topic/64794-list-db-contents/
Share on other sites

I don't think this is the right section for the 'I have no code right now, and I have no idea how to do it, but will you please do it for me?' approach....

 

 

Anyway, what you're gonna want to do is select the clan id and name from the table, then spit it out into a drop down box like so:

 

$q = mysql_query('SELECT clan_id, name FROM clans');

echo '<select name="clan">';

while($r = mysql_fetch_assoc($q)) {
echo '<option value="'.$r['clan_id'].'">'.$r['name'].'</option>';
}
echo '</select>';

 

Then on your processing page to insert the new user info, you could just check that the clan id was numeric and it existed....  Then, when ever you wanted to say what clan a member belonged to, you could INNER JOIN tables to get the clan name.

Link to comment
https://forums.phpfreaks.com/topic/64794-list-db-contents/#findComment-323219
Share on other sites

I think this is what you are wanting. You will change the field name in the sql query to match your name field in the db

 

<?php
$dbhost = 'localhost'; 
$dbusername = 'username'; 
$dbpasswd = 'pass'; 
$database_name = 'your_database'; 

$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")  
    or die ("Couldn't connect to server."); 
$db = mysql_select_db("$database_name", $connection) 
    or die("Couldn't select database.");

echo '<select name="select">'
$sql = "SELECT `name` FROM `your_table`";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) < 1) {
   echo "<option value='none'>No names to display</option>";
} else {
   while($rw = mysql_fetch_assoc($res)) {
        echo "<option value='{$rw['name']}'>{$rw['name']}</option>";
   }
}
echo "</select>";
mysql_close($connection);
?>

 

You will have to change the table name and the field name in both the query and $rw['name'] to match your db field and table name

 

edit

corbin beat me to it but here is basically the same thing

Link to comment
https://forums.phpfreaks.com/topic/64794-list-db-contents/#findComment-323222
Share on other sites

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.