PHP refresh page

A

Anonymous

Guest
Hi, how can i refresh the page using PHP? Going to be like this:

if ($submit) {
mysql_query("UPDATE my_table SET all='$thecrap'") or die("Query sux");
----then the refresh code comes-----this way the form boxes will show the updated info, and not the old stuff-----
}


Thanks
 
Code:
if condition
{
    header("Location: ".$_SERVER['PHP_SELF']);
}
else
{
}
 
Hello again, when i do that, it gives me an error: Warning: Cannot modify header information - headers already sent by

Might you know how to fix that?

BTW: I have another problem, *perhaps* you may be able to fix it...

If you read my comments in the code, then read whats after, it will be easier to understand.


Code:
<?php 
// all the basic stuff 
$connect = mysql_connect("localhost", "asdf", "asdf") or die("could not connect to server"); 
$db_select = mysql_select_db("asdf") or die("could not select the database"); 
$result = mysql_query("SELECT classlist FROM itemsearch WHERE id = " . $itemsid) or die ('Query was not runned'); 
while($grow = mysql_fetch_array($result)) 
{ 
extract($grow, EXTR_PREFIX_ALL, "Ta"); /* im separating the array, to get it ready for the foreach () */ 
foreach (array($Ta_classlist) as $value) { /*now for each number, im getting a name from another table, so the number 1 is has a name, 2, 3, etc, and i will echo it later */

$newresult = mysql_query("SELECT classname FROM classes WHERE classid = " . $value) or die ('Could not run 5 query'); 
    while($line = mysql_fetch_array($newresult)) 
    { 
         echo("$line[classname]");; /* now we echo the name of the numbers we got from the list */
    } 
}   
} 
?>


Ok, this all works when the classlist is just one number, but how do i make the DB look for many numbers? like 5, 3, 2, 1 etc
Ive tried "5", "4" and 5, 4 and 5 4

Or is there something i have to, or can, do in the PHP?
Thanks
 
You could put the search items in an array and search for them seperately.

Like this:

Code:
<?php
$connect = mysql_connect("localhost", "asdf", "asdf") or die("could not connect to server");
$db_select = mysql_select_db("asdf") or die("could not select the database");
$search = array(2, 5, 6, 3);

foreach ($search as $itemsid) {
	$result = mysql_query("SELECT classlist FROM itemsearch WHERE id = " . $itemsid) or die ('Query was not runned');

	while($grow = mysql_fetch_array($result)) {
		extract($grow, EXTR_PREFIX_ALL, "Ta"); /* im separating the array, to get it ready for the foreach () */

		foreach (array($Ta_classlist) as $value) { /*now for each number, im getting a name from another table, so the number 1 is has a name, 2, 3, etc, and i will echo it later */

			$newresult = mysql_query("SELECT classname FROM classes WHERE classid = " . $value) or die ('Could not run 5 query');

    		while($line = mysql_fetch_array($newresult)) {
         		echo("$line[classname]");; /* now we echo the name of the numbers we got from the list */

   			 }
		}   
	}	
	
}

?>

Or make a big array then use that:

Code:
<?php

$search = array(2, 5, 3, 6);

$details = array();

foreach ($search as $value) {
	$result = mysql_query("WHATEVER.....", $link);
	while ($row = mysql_fetch_array($result)) {
		$details[] = $row;
	}
}


//DO SOMETHING WITH $details

?>

I hope this is what you were asking for.
 
Hello, actually the search has just been made, now the user is going to the display page.
to search.php, user clicks an item & goes to display.php?itemID=5, each item has a list of numbers, each number represents a name, like John Doe. The SQL gets the list as shown below.

mysql_query("SELECT classlist FROM itemsearch WHERE id = " . $itemsid) or die ('Query was not runned');
------
then, the foreach () separates each number, and "for each" number, another SQL is done. this one is also below..

mysql_query("SELECT classname FROM classes WHERE classid = " . $value) or die ('Could not run 5 query');
--------

That SQL gets the classname, it finds the name by the numbers in classlist.

--------------------
The problem:

That code works perfectly fine, except that it can only do 1 number.
I am wondering what I have to do to do say 5-10 numbers...

--Thanks--
 
I'm a little late to the discussion, but anyway..

You can pass multiple numbers in the URL as an array:

http://site.com/display.php?itemID[]=5&itemID[]=7&itemID[]=9

And you can fetch multiple records using a query like this:

Code:
SELECT classlist FROM itemsearch WHERE id = 5 OR id = 7 OR id = 9;
 
Back
Top