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.

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.

anyone able to offer a solution please?

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");

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

ya, i got your problem ! :)

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.

I wonder (:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.