I am trying to select three variables from my mySQL table. I have am creating a function so that I can display the three values later in a foreach loop. I am trying to pull the variables url, name, and s_name.
I can't seem to get all three variables in one array. Could you please help me figure out how to improve the function and then show me how to display it.
Here is the function:
Expand|Select|Wrap|Line Numbers
- function getURL(){
- $sql = 'SELECT * FROM searches LIMIT 10';
- $result = mysql_query( $sql );
- $searches = array();
- while( $obj = mysql_fetch_object( $result ) ){
- $searches[ $obj->url ] = $obj->name, $obj->s_name;
- }
- return $searches;
- }
Expand|Select|Wrap|Line Numbers
- <?php foreach( $searches as $url => $name, $s_name ) { ?>
- <a href="<?= $url; ?>"><?= $name; ?>, <?= $s_name ?></a>
- <?php } ?>