473,569 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display multiple random rows from a table if nothing found in search

66 New Member
Hi all, ive got a search function running on a database, the action performed by the form is shown below, within the 'else' statement i would like to show roughly 5 random rows from the sql table (alternative products) if you like.

please find below the script im currently running for the search, the else statment just shows 'no results found' message at the moment.

many thanks in advance for any who can help:

Expand|Select|Wrap|Line Numbers
  1.   <table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
  2.     <tr>
  3.       <td><img src="graphics/sunflowerbanner.jpg" width="830" height="227" /></td>
  4.     </tr>
  5.     <tr>
  6.       <td><?php
  7.     include "flowermatchdbcnx.php";
  8.      $r = @$_POST['occcas']; //users choice... e.g. birthday, anniversary etc.
  9.      $s = @$_POST['style']; //display type... modern or classic.
  10.      $p = @$_POST['price']; //price, need to be within the price range. 
  11.      $t = @$_POST['type']; //flower suitability.... mother father collegue etc.
  12.      $pak = @$_POST['pacakge']; //flowers packaging
  13.  
  14.  
  15.  
  16.     //The query to the database
  17.  
  18.  
  19.  
  20.     $query = ("SELECT * FROM products WHERE style IN ('$s') AND occcas IN ('$r') AND type IN ('$t') AND pacakge IN ('$pak') AND price IN ('$p')");
  21.  
  22.  
  23.     $result = mysql_query($query);
  24.     $result_count = mysql_num_rows($result);
  25.     //while loop to go through database table search all matching records.
  26.     if ($row = mysql_fetch_array($result)) {
  27.     //start of table... sets table headers
  28.     echo "<table border='1'><tr><td>name</td><td>type</td></tr>";
  29.     //returns results and puts them in ajoining table
  30.     printf ("<tr><td>%s</td><td>%s</td><td>%s</td></tr></table>",$row[8], $row[6], $row[5]);
  31.  
  32. }else { 
  33.     echo "there were no matches found, please find some alternatives below"; 
  34. }
  35.  
  36. ?></td>
  37.     </tr>
  38.     <tr>
  39.       <td><div align="center"><?PHP echo "$result_count\n"; ?></div></td>
  40.     </tr>
  41.   </table>
  42.  
  43.  
  44.  
  45.  
Dec 4 '07 #1
1 1727
stepterr
157 New Member
You could do another query using Rand() within your query. Such as:
[PHP]
$query = "SELECT * FROM table ORDER BY Rand() LIMIT 2";
[/PHP]
Dec 15 '07 #2

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

Similar topics

2
2593
by: Beyonder | last post by:
I have five tables in my database, there are actually NO common fields between them, not even a KEY or ID or anything like that, except for the "body" of a blob field. and that text is not identical, just a portion of that text is identical. each table has 5 fields, all different except the blob, which is called "message", so normally I use...
3
1885
by: Voetleuce en f?nsievry | last post by:
G'day I'm looking for a script that can search multiple instances of Google (or other search engines optionally). The user types in a single word in the text field, presses ENTER or the submit button, and the browser launches several instances of Google with the single word + other search terms. I would like to have this script because...
18
3329
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the listbox display 2 columns information...
32
14783
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
0
5805
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new...
2
7039
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created...
0
1990
by: simon | last post by:
hello, relatively new to .net, i'm using vb.net and the 2.0 .net platform I'm trying to display a grid that has a text box on the left in one cell (with a hidden ID), which will be associated to multiple rows (events) on the right. each row on the right will also have a text box ------------------------------------------------------- ...
2
1512
by: assgar | last post by:
Hi Multiple rows of dynamically created data is retrived from the database and displayed properly. When I get 50 rows displayed scrolling is necessary. The problem is when I scroll to see the items at the bottom of the list the rows get blurred (jumbled). To be specific at the top and bottom rows of the list are displayed properly but in...
1
13639
by: imrannawabkhan | last post by:
I was working on project page where I required to get the row data from mySql db in side the table cells. I knew how to use the php script to get the row data into the table cells like. Id | Name | Exame | Nos 1 | Nasir | Maths | 25 2 | Abdulla | Maths | 50...
0
7695
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...
0
7612
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...
0
8119
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...
1
7668
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...
0
7964
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...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.