You are here: function to simplify data « PHP Programming Language « IT news, forums, messages
function to simplify data

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация