0

Hi there,
I have some code on a page to extract info from a database (like a back end system) and I just wondered if there was anyway I could do a shortcut around the code to avoid doing multiple SELECT statements.

e.g

<?php 
	$result = mysql_query("SELECT * FROM quackedup WHERE contid='[B]topsummary[/B]'") or die(mysql_error());
	$row = mysql_fetch_array($result);
	echo $row['content']
	?>

but then, further down the page, I will need to do another select for something else, and something else.

<?php 
	$result = mysql_query("SELECT * FROM quackedup WHERE contid='[B]firstpic[/B]'") or die(mysql_error());
	$row = mysql_fetch_array($result);
	echo $row['content']
	?>
<?php 
	$result = mysql_query("SELECT * FROM quackedup WHERE contid='[B]secondpic[/B]'") or die(mysql_error());
	$row = mysql_fetch_array($result);
	echo $row['content']
	?>

is there a way to just do 1 global 'SELECT * FROM quackedup' and then change what I output by using the echo statement.
what I want to do is like the below.

echo $row WHERE contid='secondpic'

Thanks very much.

Edited by Chubbymouse: n/a

4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by gokhanfil
0

I think that you have three choices.
1. If there is some common factor that links these records together in the database, then you can use that as a selection criteria.

2. If you can collect your criteria before issuing the select, then it can be in the form:

... WHERE contid='firstpic' or contid='secondpic' ...

3. If your criteria is based on input from some source or a table then use a While loop rather than code all the selects individually.

0

all the content is ordered by pageid, these being on 'home', all content is stored in 'content' but all content is different and is in different areas throughout the page.

0

would u like to do using function like this ??

function displaycontent($contid)
{
    $row=mysql_fetch_array(mysql_query("SELECT * FROM quackedup WHERE contid='".$contid."'"));
    echo $row['id'];
}
displaycontent("topsummary");
displaycontent("firstpic");
displaycontent("secondpic");
0

thanks for the reply,
i don't mind how I go about it just as long as i don't have to query the database every time with each separate WHERE's :)

0

the solution was to use the individual content as columns, not as rows.
topsumm firstpic secondpic

and then have them as VARCHAR and just 1 row.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.