[HELP] Retrieving MYSQL data from search putting into forms.

Status
Not open for further replies.

LeCeejay

Member
Dec 25, 2010
122
17
Ik spam spam spam... But here's what Iw ant to know;

MYSQL:
If I input say, 3 things into my form today, and on my 'List all inputs today', how would I do that? So like how would I put (in C#/Pawn way:

"if(date == curdate)
{
DISPLAY RESULTS LYK
}
else
{
No jobs booked today
}"

???

NEW:
I'm a bit stuck xD, I have a search tool How do I make it so when I search and press enter, it comes up with results (II've got this bit) :p, But how do I transfer the RESULTS to a new form to update it?

I shall post my codes for both if needed ;3
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,933
1) Give each new "job" that is inserted a timestamp.

2) What exactly are you searching for? something specific? or something within a field?
 

LeCeejay

Member
Dec 25, 2010
122
17
They have a timestamp/time. I just need to know how to only recall those that are inputted on that day.

2)
I have a search tool, It searches 3 things for a search term you put in, these are 'Name' 'Ward' and 'Destination', if your search term comes back with results, It lists them.

I want to know how I can make a link such as 'Edit' and it will transfer the data from that job into my /update.php page, so it can be edited
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,933
If you want the last 24 hours you'd do:
PHP:
$timestamp = time() - (24 * 60 * 60);

Other wise, if you wanted just what was posted that day (based on PHP's default timezone), you could do this.
PHP:
$timestamp = mktime(0, 0, 0);

Your query would look like this:

PHP:
$mysql->query('SELECT * FROM `table` WHERE `timestamp` > ' . $timestamp);

----------------------------------------------------------

You could have a link going to something like:
Code:
edit.php?id=?

That way you know what you're editing.
 

LeCeejay

Member
Dec 25, 2010
122
17
If you want the last 24 hours you'd do:
PHP:
$timestamp = time() - (24 * 60 * 60);

Other wise, if you wanted just what was posted that day (based on PHP's default timezone), you could do this.
PHP:
$timestamp = mktime(0, 0, 0);

Your query would look like this:

PHP:
$mysql->query('SELECT * FROM `table` WHERE `timestamp` > ' . $timestamp);

----------------------------------------------------------

You could have a link going to something like:
Code:
edit.php?id=?

That way you know what you're editing.


I'll have a look at the first

2nd:
Right so.

I want to make a unique ID for EACH job that's made, so like it starts at 1 and every job is +1, so 1, 2, ,3 etc..

How would I go about doing this.

Currently when i create a job the id is 'null', how do I make the number system thing?
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,934
3,933
Right so.

I want to make a unique ID for EACH job that's made, so like it starts at 1 and every job is +1, so 1, 2, ,3 etc..

How would I go about doing this.

Currently when i create a job the id is 'null', how do I make the number system thing?
You set the field to auto increment.

 

LeCeejay

Member
Dec 25, 2010
122
17
Did your 'time' thing, this is what happened;

Notice: There was an error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`name` LIKE '%1234%' ORDER BY `name`' at line 1
SQL Was: `name` LIKE '%1234%' ORDER BY `name` in C:\xampp\htdocs\index.php on line 43

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\index.php on line 45

Heres the lines:
PHP:
  if (count($error) < 1) {
      $searchSQL = mysql_query('SELECT * FROM `table` WHERE `timestamp` > ' . $timestamp); // 31 (The line which tells were to read from)
      // grab the search types.
      $types = array();
      $types[] = isset($_GET['body'])?"`name` LIKE '%{$searchTermDB}%'":'';
      $types[] = isset($_GET['title'])?"`ward` LIKE '%{$searchTermDB}%'":'';
      $types[] = isset($_GET['desc'])?"`destination` LIKE '%{$searchTermDB}%'":'';
      $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)
     
      if (count($type) < 1)
      $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked
      $andOr = isset($_GET['matchall'])?'AND':'OR';
      $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `name`"; // order by title.
      $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); // Line 43
 
     if (mysql_num_rows($searchResult) < 1) //45
 {
         $error[] = "No results found... Would you like to book this job? <a href='index.php'>No</a>  <a href='book.php'>Yes</a>";
      }
 else

So, how would I make this;

IT will get the date.
It will then search through the database with the 'date' as that date.
It will echo the stuff


Please?
 

brsy

nah mang
May 12, 2011
1,530
272
I have absolutely no idea in wtf you are doing, considering I can't understand your incapability of speaking english.

PHP:
 if (count($error) < 1) {
      $searchSQL = mysql_query('SELECT * FROM `table` WHERE `timestamp` > ' . $timestamp); // 31 (The line which tells were to read from)
      // grab the search types.
      $types = array();
      $types[] = isset($_GET['body'])?"`name` LIKE '%{$searchTermDB}%'":'';
      $types[] = isset($_GET['title'])?"`ward` LIKE '%{$searchTermDB}%'":'';
      $types[] = isset($_GET['desc'])?"`destination` LIKE '%{$searchTermDB}%'":'';
      $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)
   
      if (count($type) < 1)
      $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked
      $andOr = isset($_GET['matchall'])?'AND':'OR';
      $searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); // Line 43
 
    if (mysql_num_rows($searchResult) < 1) //45
{
        $error[] = "No results found... Would you like to book this job? <a href='index.php'>No</a>  <a href='book.php'>Yes</a>";
      }
else

This should work, I really can't understand anything that you are coding.
 

LeCeejay

Member
Dec 25, 2010
122
17
Okay, here's in simple terms

I want to make a page, which will display entries from the current day.
So if I book 2 jobs yesterday, and 2 jobs today - I only want this to show the jobs booked TODAY.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Insert timestamps into the database for EACH record, and use a code like this or something, I think...

PHP:
$books = $db->query( "SELECT * FROM `books` WHERE `TimeStamp` < '" . (time() - (24*60*60)) . "'" );

I'm not entirely sure, I'm not the best at dealing with 'Date/Time' in PHP.
 
Status
Not open for further replies.

Users who are viewing this thread

Top