[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to write a simple query

Posted on 2009-05-19
5
Medium Priority
?
200 Views
Last Modified: 2012-05-07
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
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:termlimit
ID: 24428314
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
 
LVL 2

Expert Comment

by:miyosia
ID: 24428318
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
 

Author Comment

by:phillystyle123
ID: 24428323
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
 
LVL 2

Accepted Solution

by:
miyosia earned 2000 total points
ID: 24428392
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
 

Author Closing Comment

by:phillystyle123
ID: 31583331
thank you!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question