Hello,
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:
And here is how I plan on displaying it:
Any assistance would be greatly appreciated.
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:
Code:
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;
}
Code:
<?php foreach( $searches as $url => $name, $s_name ) { ?>
<a href="<?= $url; ?>"><?= $name; ?>, <?= $s_name ?></a>
<?php } ?>
Comment