473,666 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add link to search results (<a href="">)

250 Contributor
In my php page there is a search function and when user search it will display table containing search results. I want to add
Expand|Select|Wrap|Line Numbers
  1. <a href ..></a>
  2.  
. Because when user click one record I want to pass values to ajax page.
to those results. But my code is not working. Please help me.This is my code.
Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_array($result))
  2.     {
  3.     echo "<a href='javascript:void(0);' onclick=\"LookupVehicle('$VehicleNo','$VehicleType','$VehicleMake','$Price'); return false;\">";
  4.         $array = array('VehicleNo','VehicleType','VehicleMake','Price');
  5.         foreach ($array as $v)
  6.         $$v = $row[$v];?>
  7.  
  8.           <tr>
  9. <?php
  10.  
  11.                 foreach ($array as $v)
  12.                 echo "<td height=20 cursor: pointer;'> &nbsp;".$$v."</td>";
  13.         ?>
  14.         </a>
  15.          </tr>
  16.  
  17.     <?php }
  18.  
Oct 8 '09 #1
1 4957
Atli
5,058 Recognized Expert Expert
Hey.

Not feeling particularly articulate today, so I just commented your code :-]
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. while($row = mysql_fetch_array($result)) 
  3. {
  4.     // Isn't this supposed to be *after* you crate the variables you are echoing?
  5.     // And why is the ending </a> somewhere way inside the <tr> tag?
  6.     echo "<a href='javascript:void(0);' onclick=\"LookupVehicle('$VehicleNo','$VehicleType','$VehicleMake','$Price'); return false;\">";
  7.  
  8.     // Why bother with this? You can just as easilly use
  9.     // "$row['VehicleNo']" as "$VehicleNo"
  10.     $array = array('VehicleNo','VehicleType','VehicleMake','Price');
  11.     foreach ($array as $v){
  12.         $$v = $row[$v];
  13.     }
  14.     // P.S. Note the addition of the brackets to your foreach loop.
  15.     // Always use brackets. Leaving them out is just sloppy.
  16.  
  17.     // No poing exiting the <?php block just to output 4 letters.
  18.     // Echo was created for a reason ;-)
  19.     echo "<tr>";
  20.  
  21.     foreach ($array as $v) {
  22.         echo "<td height=20 cursor: pointer;'> &nbsp;".$$v."</td>";
  23.     }
  24.     // Again, note the added brackets to the loop.
  25.  
  26.     // 9 letters this time. Still not worth exiting the PHP block ;-)
  27.     // What's with the random </a> here? Shouldn't it be up there with the
  28.     // rest of the <a> tag?
  29.     // Unless you are trying to make the entire row a link, in which case
  30.     // you should use the <tr> onclick event, not enclose the <tr> in a <a> tag.
  31.     echo "</a></tr>";
  32. }
  33. ?>
Oct 8 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2274
by: Nel | last post by:
Hi all, I have been searching for some clues as to how to show a substring from a database search. $pagetitle = "Page Title"; $pagetext = "This is <b>a typical</b> string that would be stored<br>in the database.";
2
3525
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned from my search and how many records I have set it to display per page. All great so far, HOWEVER..... When you click the next link to see the next 10 results on the next page, it just dumps the search details and pulls up all the records in the...
5
2975
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine (a wicked phrase). Some but not all of the words of that phrase exist in my website. I reported it and they removed the link but did not give explanations.
4
3481
by: Dica | last post by:
i apologize for what is no doubt a very rudimentary question, but i'm still trying to wrap my brain around .net coding habits. in classic asp, if i wanted to show search results, i'd just post the form data over to another page or call a showSearchResults sub on the search page. in .net, i can't post to another page, so i need to show the search results on the same page as the search form page. i could write a sub in my code behind that...
1
1675
by: sqlster | last post by:
I have a search page which renders results upon post back based on certain input criteria. Clicking on a link on a search result such as order number navigates to the order detail screen. What is the best away to program behind the "Back to search results" screen on order detail screen. Should I session stored the input criteria on search page so that when it is invoked from order detail screen, it would pull out that information and...
0
1541
by: =?Utf-8?B?Qm9ubmll?= | last post by:
I have a basic ASP / Index Server search page. I have a web site contained in a subdirectory in the root of a main web site. What I’m trying to do is force the search page in the subdirectory, conduct its search ONLY in the subdirectory, and NOT display results from the parent/root. (Note: there is also a similar search page for the main site, in the root, which I am having no problem excluding the subdirectory from its search results.) ...
4
3519
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link that navigates to a details page. When I try to go back to the search results page i get "Page cannot be displayed" error. How do i go back to the search results and have the search criteria and dataview unchanged? i.e. The behaviour I'm...
3
1486
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank screen. I think it might have something to do with resetting the $found variable. Can you have a quick look? any suggestions would be greatly appreciated. <? if ($_GET) $vars=$_GET; else $vars=$_POST; $found = $vars;
5
1616
by: moorcroft | last post by:
Hi I have developed an application that people can use to search for planning applications. The way it works is that once search criteria has been selected and submit is hit, the server will save the search results in an xml file and then redirect to the view search results screen. This screen checks if the xml file exists and if it does, it displays the results, otherwise it says results have expired. The problem is the fact that this is...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.