Если вы используете CMS, как, например, AlientWebguy, вы никогда не узнаете ... и я предполагаю, что вы здесь, чтобы учиться. Вы должны начать с учебника, хотя, поскольку это довольно простой материал.
Но для достижения того, что вы пытаетесь сделать - если бы я был новичком - вот что я буду делать. Я не дам вам ваш код, но он определенно достаточно близко, чтобы вы могли понять это.
Я бы файл с именем functions.php, который включал следующее:
<?PHP
// these are freebies. You don't need to understand them yet.
function sqlarr($sql, $numass=MYSQL_BOTH) {
// MYSQL_NUM MYSQL_ASSOC MYSQL_BOTH
$got = array();
$result=mysql_query($sql) or die("$sql: " . mysql_error());
if(mysql_num_rows($result) == 0)
return $got;
mysql_data_seek($result, 0);
while ($row = mysql_fetch_array($result, $numass)) {
array_push($got, $row);
}
return $got;
}
// Sql fetch assoc
function sqlassoc($sql){
$query = mysql_query($sql) or die("$sql:". mysql_error());
$row = mysql_fetch_assoc($query);
return $row;
}
function sqlrow($sql){
$query = mysql_query($sql) or die("$sql:". mysql_error());
$row = mysql_fetch_row($query);
return $row;
}
function sqlquery($sql){
$query = mysql_query($sql) or die("$sql:". mysql_error());
return $row;
}
?>
Затем на файл, который я собирался выводить данные, я бы поставил следующее:
<?PHP include('./functions.php');
// It sounds like you are already connected to your database, so I'm going to skip that. If you need it, add a comment.
$sql = "SELECT `colNames`, `colName2` FROm `tableName` WHERE `col` = 'condition' ";
// obviously change this to your names, such as `itemNumber`
$results = sqlarr($sql); // Now results is going to automatically contain a 2D array.
echo '<pre>'; print_r($results); echo '</pre>';
/* this is just to show you what is happening so far. You should get in the habit of using things like this to debug. A lot of people prefer var_dump instead of print_r. I use both because var_dump is harder to read.
// Result should be returning something like this:
// array(
[0] => array(
[0] => 'ABC123',
["itemNumber"] => 'ABC123',
[1] => 'http://www.abc.com',
["link"] => 'http://www.abc.com'),
[1] => array(...)
)
// the first level - the [0] => array( or the [1] => array(part - corresponds to a row in your database
// so now we need a way to filter through those rows. Look up php.net/for or php.net/foreach to see how to accomplish that. A lot of people use php.net/while too, but I don't prefer that personally. */
?>
<html>
<body>
<table>
<?PHP
foreach($results as $row){ // this is turning $result[0] => array( into $row. So now we can access $result[0]['linkName'] as $row['linkName']
echo '<tr><td>'.$row['linkName'].'</td></tr>';
} // foreach $row - dont forget to close your curly bracket. Good practice is to always close it as soon as you open it, and to put a comment after it like I just did letting you know what it goes to
?>
</table>
</body>
</html>
Если что-то здесь не имеет смысла, просто оставляйте комментарий. Я рад объяснить.
+1, теперь у вас есть 8 rep. – AlienWebguy