Php mysql query

apps

#1

Okay, I cannot still logon as a forum member, but I do need to say more about my query. I cannot even call a function for a string that says I made it to the database. It never passes any results.

my code is:

<?php function query_select() { // $name="institutionname"; // $query="SELECT 'institutionname' FROM 'mysql_tbl' WHERE paidflag > '0' AND paidflag < '999999'"; // $default = ""; // $conn = db_connect(); // $result = mysql_query($query, $conn); // if (!$result) // return('No results found'); // $select = ""; // $select .= "Choose"; // for ($i=0; $i < mysql_num_rows($result); $i++) { // $row_code = mysql_result($result, $i, 0); // $row_desc = mysql_result($result, $i, 1); // $select .= "".$row_desc.""; // } // $select = "This is where the select box goes"; return('Select box goes here'); } ?>

#2

Uhm, one obvious mistake is you forgot to close the SELECT element. Here is a working script.

[code]<?php

function name_select($dbh, $default) {

// execute our query

$query = “SELECT institutionname FROM mysql_tbl WHERE paidflag > ‘0’ AND paidflag < ‘999999’”;
$rows = mysql_query($query, $dbh);

// if no rows, return error message

if (!$rows) {
return “

No rows returned?!?

” . mysql_error($dbh) . “

”;
}

// construct SELECT element

$result =
"" .
"– Choose –";
for ($i = 0; $i < mysql_num_rows($rows); $i++) {
$row_code = mysql_result($rows, $i, 0);
$row_desc = mysql_result($rows, $i, 1);
$result .= “<option value=’$row_code’”;
if ($row_code == $default) {
$result .= " selected";
}
$result .= “>$row_desc”;
}

$result .= “”;

return $result;
}

$db_username = ‘duh’;
$db_password = ‘duh’;
$db_hostname = ‘duh’;
$db_database = ‘duh’;

$dbh = mysql_connect($db_hostname, $db_username, $db_password);
mysql_select_db($db_database);

echo “”;
echo name_select($dbh);
echo “”;

?>[/code] :cool: Perl / MySQL / HTML+CSS