Posted by windandwaves on 09/04/05 01:10
Hi Folk
I seem to be writing the following a lot (this is just one of many
examples):
$sql = 'SELECT `ID`, `NAM` FROM HEP ORDER BY `ID`';
$query = mysql_query($sql);
while($row = mysql_fetch_row($query)) {
$ei = $row[0];
$en = $row[1];
$content .= '<li><a href="test.php?i='.$data("ID").......
}
I want to write a function like this
function getdata($sql) {
$query = mysql_query($sql);
while($row = mysql_fetch_row($query)) {
$v[$i][{name of first column in select query (e.g. ID)}] = $row[0];
$v[$i][{name of first column in select query (e.g. NAM)}] = $row[1];
$i++;
}
Then, in my code I can write something like
$sql = 'SELECT `ID`, `NAM` FROM HEP ORDER BY `ID`';
$data = getdata($sql)
while(loop through array - i have no idea how you do this - but can look it
up) {
$content .= '<li><a href="test.php?i='.$data("ID").......
}
What is the most efficient way to write such a function???
Any help appreciated.
- Nicolaas
Navigation:
[Reply to this message]
|