PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
function show($col){
$q = mysql_query("SELECT $col FROM categorie");
$qw = mysql_fetch_array($q);
$this->unu = $qw;
return $this->unu;
}
?>
Your function is incorrect. You are returning an array which contains (probably) the value for $col (in your example 'titlu') and the field value of 'titlu'.
dotphp wrote:If I want to show how many rows are in that table with the following code:
Do you want to show the amount of rows in the table (in total) ?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
mysql_fetch_array() will give you an array representation of the next row in your result resource. The first time you use it, you get the first row. mysql_fetch_array() is special in the sense that it gives you both an indexed array and an associative array in one. So, what you get is something along the lines of:
function show($col){
$q = mysql_query("SELECT $col FROM categorie");
$qw = array();
while ($data = mysql_fetch_assoc($q)) $qw[] = $data; // This pulls all data instead of just one
$this->unu = $qw;
return $this->unu;
}
$val is an array because $data is an array. It looks like you want show() to return an array of values instead of an array of arrays, so make this modification: