Web Analytics Made Easy -
StatCounter Search a table - CodingForum

Announcement

Collapse
No announcement yet.

Search a table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Search a table

    Hi,

    I'm fairly new to mysql. I am using PHP as well.
    What I have is a table of bookings for rooms. I am able to query the database. But what I want to do is look at each row in the table and see if the vaules in the row match what the user has selected. The fields in the table are:

    (booking, username, roomnum, startdate, enddate, starttime, endtime)

    Is there a function that I can set up a loop to go through the table row by row and compare the values.

    If a row in the table matches what the user selected i want the outcome to be boolean, to say true.

    I how can i form an sql query to say something like

    if exists (row where values match)

    echo 'booked'

    Can anyone help me form this kind of query please??

  • #2
    Not just

    SELECT var1, var2 FROM table WHERE var3='yourvalue'

    ?

    Would youlike to only return the matched records, or all records?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      For each matched record i want an output of 'Booked'
      So if a row in the table matches what the user selected i want a boolean value to be returned. That is why i was thinking of an 'exist'being in the query. Is that right?

      There are some other complicated things i wish to do with comparisons but i am unsure of how to explain them.


      thanks

      Comment


      • #4
        Originally posted by raf
        Would youlike to only return the matched records, or all records?
        If you only need the 'booked' records, then you don't need to do anythin gin your sql-statement, but you then add the booked when you process the recordset inside your server side scripting (PHP or so)

        If you want aal records returned, then you can still add the bookend when you proces the recordset, by compairing the value there

        like
        PHP Code:
        if ($row['booking'] == 1){
          echo 
        'Booked';
        } else {
           echo 
        'Free';

        (supposing you want to check against column 'booking' and 1 = booked)
        or you can do it inside the sql-statement like

        select REPLACE(booking,'1','Booked') from table

        which way to choose depends on the other action you'd perform on the records.
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment

        Working...
        X