I don’t know what I did wrong. Your help is appreciated.
require('_db.php'); // get the db connection info
$metricsql = "SELECT * FROM $metrics_tableName ORDER BY '$metrics_order_col'";
$metrics = array();
$result=mysql_query($metricsql)or die(" Error: Could not connect to metrics table".$metricsql.mysql_error());
//Begin metrics loop
while( $row = mysql_fetch_array($result)){
print_r($row);
//return $metrics[$i]['metric_label'].'here';
print $row['metric_label'].'here';
return $row['metric_label'];
return count($row);
}//end metrics loop
}
can’t help you with the php, but you should be aware that this won’t work the way you think it will –
ORDER BY '$metrics_order_col'
no matter what value $metrics_order_col might have, if you put quotes around it, it’s a string, and then all the rows will be sorted by the same value, i.e. unpredictably
@ Decowski. It’s in a function. I was just testing the return to see if I would get different values. Commenting out one of the returns doesn’t seem to make a difference. hmm…
function show_metrics(){
require('_db.php'); // get the db connection info
// get votes, values, ips for the current rating bar
$metricsql = "SELECT * FROM $metrics_tableName ORDER BY $metrics_order_col ASC";
$metrics = array();
$result=mysql_query($metricsql)or die(" Error: Could not connect to metrics table</BR>
The offending query was<pre>".$metricsql."</pre>".$metricsql.mysql_error());
//Begin metrics loop
while( $row = mysql_fetch_array($result)){
print_r($row);
//return $metrics[$i]['metric_label'].'here';
print $row['metric_label'].'here';
return $row['metric_label'];
//return count($row);
}//end metrics loop
}
echo the sql query in $metricsql then access the db via phpmyadmin and run the sql against the db in phpmyadmin, does it still only give one row? In any case that should 100% rule out any errors in your php
Could someone please explain to me why crmalibu’s suggestion worked but this example here wouldn’t works without making $row and array via row#= array() and $row =?
It would better my understanding so I could avoid these things in the figure. Thank you.
Example : select.php
Source code : select.phps, contact.txt
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT name, subject, message FROM contact";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Name :{$row['name']} <br>" .
"Subject : {$row['subject']} <br>" .
"Message : {$row['message']} <br><br>";
}
include 'closedb.php';
?>