Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-02-11, 11:43 PM
Junior Member
 
Join Date: Feb 2006
Posts: 3
txtimmer87
Default

I am writing a code in which i need to find a value in my MySQL database. If the value is not there, however, I want the first value that is listed listed below my search value.

Any help would be a lifesaver!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2006-02-12, 11:16 AM
Junior Member
 
Join Date: Feb 2006
Posts: 3
txtimmer87
Default

I've tried the following method, but it returns the first value of my entire database.
Here's what I've written:

$get = "SELECT myfield FROM mytable WHERE myfield <= myvalue LIMIT 1";
$search = mysql_query($get) or die(mysql_error());
$file = mysql_result($search, 0);
echo "
$file";
Reply With Quote
  #3 (permalink)  
Old 2006-02-12, 11:33 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

A better way would be to use sort to sort against the results. This would only work if you are looking for a single value though.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #4 (permalink)  
Old 2006-02-12, 12:39 PM
Junior Member
 
Join Date: Feb 2006
Posts: 3
txtimmer87
Default

Hey that worked!
Here's the new script:

$get = "SELECT myfield FROM mytable WHERE myfield <= myvalue ORDER BY myfield DESC LIMIT 1";
$search = mysql_query($get) or die(mysql_error());
$file = mysql_result($search, 0);
echo "
$file";
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:12 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.