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.


	$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.

	$result = mysql_query("SELECT * FROM quackedup WHERE contid='[B]firstpic[/B]'") or die(mysql_error());
	$row = mysql_fetch_array($result);
	echo $row['content']
	$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

7 Years
Discussion Span
Last Post by gokhanfil

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.


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.


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'];

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 :)


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.