View Full Version : php query display all
shwaza
12-12-2004, 01:34 PM
When i put in SELECT * FROM `usersubmitted` WHERE `blah` = '$p
what do i put in the place where blah is to make it display all the rows.
To display all of the rows, leave "WHERE `blah` = '$p'" out-- just use the syntax "SELECT * FROM `table`"
Tim :)
shwaza
12-12-2004, 06:00 PM
ok thanks
EDIT: oh yeah i have another question, it's not really on the same topic, but how would i make stuff be shown from a table without having ?p=blah or something at the end? could i just make it display at say, home.php?
mahangee
12-12-2004, 06:37 PM
Yes you could
$query = mysql_query("SELECT * FROM 'usersubmitted'");
while($row=mysql_fetch_array($query)){
$field_1 = $row["field_1"];
$field_2 = $row["field_2"]; //ETC
echo $field_1;
echo $field_2;//ETC
}
shwaza
12-15-2004, 07:10 PM
hmm ok i have another question, is it possible to make it so that if nothing has been defined at say blah.php it would automatically display blah.php?p=blah by default without effecting the content at blah.php?p=moreblah or something
mahangee
12-15-2004, 07:35 PM
Yes I believe it is. So what you want is if nothing is defined at p for it to show something, and if p is defined then for it to show something else?
shwaza
12-15-2004, 08:48 PM
well what i wanted for it to do was if there was nothing defined for it to display p=home by default, but i already got tim to help me, thanks anyway:)
TjeerdJan
12-15-2004, 08:53 PM
Originally posted by shwaza+Dec 12 2004, 04:34 PM--><div class='quotetop'>QUOTE(shwaza @ Dec 12 2004, 04:34 PM)</div><div class='quotemain'>When i put in SELECT * FROM `usersubmitted` WHERE `blah` = '$p
what do i put in the place where blah is to make it display all the rows.
17353
[/b]
Well when you make a query you should always use the where statement.
the where condition has to return true to show a value. So if you use:
"SELECT * FROM `usersubmitted` WHERE 1 "
It will show all coloms from all rows in table usersubmitted.
<!--QuoteBegin-shwaza@Dec 15 2004, 10:10 PM
hmm ok i have another question, is it possible to make it so that if nothing has been defined at say blah.php it would automatically display blah.php?p=blah by default without effecting the content at blah.php?p=moreblah or something
17953
[/quote]
yes this is possible:
<?php
if (isset($_GET['id'])==False){
do the things you want to do if ?id= is not set eg. $id="standard value";
} else {
do the things you want to do if ?id= is set eg. $id=$_GET['id'];
}
?>
this example checks if the ?id= is set or not. Change the normal text i put in.
Hope this helps u a bit
shwaza
12-16-2004, 01:18 AM
Ok, im tryin to do this, with the display all, and im wondering what is wrong with this.
<?php
mysql_connect("localhost", "shwaza_shwaza", "******") or die("We are having troubles with the site at the moment.");
mysql_select_db("shwaza_p") or die("We are having troubles with the site at the moment.");
$result = mysql_query("SELECT * FROM `usersubmitted`");
if (mysql_num_rows($result))
{
echo "There was an error processing your request. Most likely, the page is missing. If you have received this from a link on this site, contact the administator.";
}
else
{
while($cPage = mysql_fetch_object($result))
{
echo $cPage->content;
}
}
?>
I know that the first part works, because when i go to edit.php i get "There was an error processing your request. Most likely, the page is missing. If you have received this from a link on this site, contact the administator.";
anyone have any ideas?
688206002
12-16-2004, 01:21 AM
Try changing
mysql_num_rows($result)
to:
mysql_num_rows($result)==0
shwaza
12-16-2004, 10:19 AM
Ah, thanks ;) i knew it was in that line, but i wasnt sure what the problem was/
EDIT: ok, something is still wrong. ill post the new code.
<?php
mysql_connect("localhost", "shwaza_shwaza", "password") or die("We are having troubles with the site at the moment.");
mysql_select_db("shwaza_p") or die("We are having troubles with the site at the moment.");
$result = mysql_query("SELECT * FROM `usersubmitted`");
if (mysql_num_rows($result))
{
echo "There was an error processing your request. *Most likely, the page is missing. *If you have received this from a link on this site, contact the administator.";
}
else
{
while($cPage = mysql_fetch_object($result)==0)
{
* *echo $cPage->content;
}
}
?>
if you wanna see what the error was, check http://shwaza.hostmatrix.org/edit.php
Oh, and also just disregaurd the thing at the top that says address and stuff of that page.
Try this:
<?php
mysql_connect("localhost", "shwaza_shwaza", "password") or die("We are having troubles with the site at the moment.");
mysql_select_db("shwaza_p") or die("We are having troubles with the site at the moment.");
$result = mysql_query("SELECT * FROM `usersubmitted`");
if (mysql_num_rows($result)==0)
{
echo "There was an error processing your request. Most likely, the page is missing. If you have received this from a link on this site, contact the administator.";
}
else
{
while($cPage = mysql_fetch_object($result))
{
echo $cPage->content;
}
}
?>
You put the ==0 in the wrong place :)
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.