• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

how to write a simple query

hi

i'm not gettng an error but i'm getting no result with this -what am i doing wrong?

$query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";

see code 4 how i'm using it:
else :
				$query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";
				
				
				echo "\t<li style=\"background:url(images/photobutton_" . $value['id'] . ".jpg) no-repeat;\"><a ".($subpage=="management" && $value['id']=="50" ? 'class="active"' : ''). "   href=\"" . menus::checksef($url) . "\" $target $active tabindex=\"" . $ak->tabindex($key) . "\" onMouseover=\"dropdownmenu(this, event, menu" . $value['id'] . ", '192px')\" onMouseout=\"delayhidemenu()\">" . $value['title'] . "</a></li>\n"; 
				if ($value['id']=="50") //this is for that tricky 2nd level submenu
				echo "<ul class=\"secMenu\">
							<li>".$row_rsSubMenu['menu_item_title']."</li>
						</ul>";
			endif;

Open in new window

0
phillystyle123
Asked:
phillystyle123
  • 2
  • 2
1 Solution
 
termlimitCommented:
You are setting the query, but it doesn't appear that you have executed the query.  All you have is the query statement, but no mysql_query statement to actually use the query.
0
 
miyosiaCommented:
I think the problem is you are only defining the query but not actually connecting to database and retrieving the data. I am not sure if you already have a code connecting to the database but assuming you already established connection prior to the code
$query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";

you then need to pass this value to the mysql_query function which retrieved the data for you. This function returns the data array so you can directly assign it to a variable like this:

$result =  mysql_query($query_rsSubMenu, $link); where $link is the connection established to the database.

you can then retrieve the per row value from the $result using $row = mysql_fetch_assoc($result)) where $row is also an array containing all data for each database row retrieved. to access the value for each data you can use the database entry name or the array index (arrangement is the same as how these data are arranged int he database)

Example: echo $row['entryID']; where entryID is a database column name..

you can try using this simple example to be able to run query in PHP.
<?php
if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
    echo 'Could not connect to mysql';
    exit;
}
if (!mysql_select_db('mysql_dbname', $link)) {
    echo 'Could not select database';
    exit;
}
$sql    = 'SELECT foo FROM bar WHERE id = 42';
$result = mysql_query($sql, $link);

if (!$result) {
    echo "DB Error, could not query the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
while ($row = mysql_fetch_assoc($result)) {
    echo $row['foo'];
}
mysql_free_result($result);
?>
0
 
phillystyle123Author Commented:
hmm - i don't get it - i've got this:

$query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";

and then i'm outputting it here:

<li>".$row_rsSubMenu['menu_item_title']."</li>

what am i doing wrong?


0
 
miyosiaCommented:
you are missing the part where you have to retrieve the data..

this code $query_rsSubMenu = "SELECT menu_item_title FROM menu_items WHERE page_parent_id ='50'";
is just assigning the query to the $query_reSubMenu variable. to be able to actually retrieve the values you need
$result =  mysql_query($query_rsSubMenu, $link); where $link is derived from $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') <- this establishes connection to the database

then to output the datause this code
while ($row_rsSubMenu = mysql_fetch_assoc($result)) {
    echo "<li>".$row_rsSubMenu['menu_item_title']."</li>"
}

0
 
phillystyle123Author Commented:
thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now