hi everyone,
I'm sorry to ask such a basic question, but I'm young and trying to learn php on my own. I bought the PHP6 Bible and I'm doing a tutorial on multiple-queries.
I followed the book exactly, but I'm not getting the right result.
here's my code:
Code: [Select]<?php require_once('Connections/mydb.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
function display_cities($database_mydb, $mydb)
{
mysql_select_db($database_mydb, $mydb);
$country_query = sprintf("Select 'id', continent, countryname from country order by continent, countryname");
$country_result = mysql_query($country_query, $mydb) or die(mysql_error());
print("<table border=1>n");
print("<tr><th>continent</th><th>country</th><th>cities</th></tr>");
while ($country_row = mysql_fetch_row($country_result))
{
$country_id = $country_row[0];
$continent = $country_row[1];
$country_name = $country_row[2];
print("<tr style='background:red'align=left valign=top>"); print("<td>$continent</td>"); print("<td>$country_name</td>");
print ("<td style='background:blue'>");
$city_query = "select cityname from city where countryID = $country_id order by cityname"; //<----Something with this line is throwing it off!
$city_result = mysql_query($city_query, $mydb) or die(mysql_error());
while ($city_row = mysql_fetch_row($city_result))
{
$city_name = $city_row[0];
print("$city_name
");
}
print("</td></tr>");
}
print("</table>n");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
display_cities($database_mydb, $mydb)
?>
</body>
</html>
I've narrowed my problem down to this line "$city_query = "select cityname from city where countryID = $country_id order by cityname";" but that's how the book shows it. But, when I change that line of code to something like "$city_query = "select cityname from city where countryID = 4 order by cityname", then I get all of the cities with a countryID of 4, but they ALL print over and over again in each <td> for the duration of the loop.
I have about 15 entries in the "city" database, and they're all supposed to be echoing into the table, inline with their corresponding country.
This has been driving me nuts for hours, and I've been searching online for an answer. I'm sure I'm overooking something very simple, but please go easy on me, this is my first time attempting this! If someone sees the problem, can you please let me know?
thanks
Sequencing or queuing parallel process
Scenario is as followsThere is one parent process say P1 and 4 child processes say A B C DProcess A starts at 3:00 pm Process B starts at 3:15 pm Process C starts at 3:30 pm Process D starts at 3:45
FAGL_FC_TRANSLATION FAS52 New GL ECC 6.0
Hello,
How to show more than 1 users with this code...
Hello,i have a table that shows users only if I, as Administrator, want to be shown. But its showing just 1 user and i want to show at least 4. If i copy the code, or use loop, its showing the same
why this query can delete duplicates ?
why this query can delete duplicates ? Anybody can give me the detailed explanation ?
PHP Upload issue
Hi guys,I have stumble across an interesting issue with my script and is doing my head in.A little background on the application.I've got a document repository site which uses Jupload to upload
I am stumped
OK. Here is what I am trying to do. I have the conditions set, and if the conditions are met, I want to randomly find a user id, and username from a table, and then store each of these names in the
Timer control causing error
I recently decided to add a timer control to an existing page that uses AJAX on my site. As soon as I added the timer control and ran my app, I started getting the following error:Description: An
asp authentication problem
Hello all,
How to ask a regex question?
Hi, I thought I'd share some of my insight after seeing too many bad questions that either get ignored, rejected, or misunderstood in this forum. I'm surprised there isn't already any
Page doesn't expand for content
Hi. I've been testing a query I made. It's here http://lapr1.6te.net/inquerito.phpThe page doesn't expand for content, it cuts most of it. What can I do to solve this?Thanks