Dynadot โ€” .com Registration $8.99

Mysql to list script

Spacemail by SpaceshipSpacemail by Spaceship
Watch

ctechguy

Established Member
Impact
0
I'm trying to make an add your own link, but i want an admin verify. Does anybody now how to take information from a mysql data base and put it in to a list.

PHP:
<form id="form1" name="form1" method="post" action="">
  <label>
  <select name="select" size="5">
    <option>data from mysql</option>
    <option>http://www.webdesigntalk.net</option>
    <option>http://www.google.com</option>
  </select>
  </label>
</form>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
It depends on your database structure but you could use something like the code below. This is assuming you have a DB structure like:

TABLE NAME :: links

id.|.url..............................|.active
--+------------------------+-------
1..|http://www.google.com..| 1
2..|http://www.yahoo.com..| 1
3..|http://www.msn.com.....| 0

PHP:
// Setup Database Handle
$conn = mysql_connect ('localhost' , $dbUser , $dbPass);
$db    = mysql_select_db ($dbName , $conn);

// Get links
$sql    = "SELECT * FROM links WHERE active = '1'";
$result = mysql_query ($sql , $conn);

// Print top part of code
print <<<HERE

 <form id="form1" name="form1" method="post" action="">
  <label>
    <select name="select" size="5"> 

HERE;

// For each link
while ($link = mysql_fetch_assoc ($result)){
  $url = $link['url'];

  print "<option>$url</option>\n";
}

// Print bottom half of code
print <<<HERE

    </select>
  </label>
</form>  

HERE;

My PHP isn't that great but I think that should work.

Tell me if you need any other help :)


Hodge
 
0
•••
Moved to programming.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back