Jump to content

[SOLVED] Problem with includes from dbase in php script


dossie

Recommended Posts

Hi,

 

i'm busy with a site which shows information out of a dbase. No problem with making a connection to the dbase or getting the information from the dbase to the site but it goes wrong when i try to get the fields into an include. I want to break my page into different includes so I might be able to change text for all pages at once.

 

Does anybode know where I go wrong?

 

<?

include('../dbaseincludes/connectioninclude.php');

include('../dbaseincludes/doctypeinclude.php');

$query = 'SELECT * FROM affiliates WHERE id="4"';

 

if ($result = mysql_query($query)){

echo "";

}

else{

echo "Something went wrong, possibly you don't see all information";

exit;

while ($rij = mysql_fetch_array($result))

{

 

// this include doesn't work

include('../dbaseincludes/metainclude.php');

 

// this echo gives the good information but when I try to get it into an include it doesn't work

echo "{$rij['town']}";

 

// these things I need in 3 different includes

echo "<h4>{$rij['name']}</h4>";

echo "adress: {$rij['adress']}<br>";

echo "website: <a href={$rij['siteUrl']} target=_blank>{$rij['name']}</a>";

 

echo "<br><br>";

echo "<h4>Opinion</h4>";

echo "<a href={$rij['siteUrl']} target=_blank>Click here for opinions</a>";

echo "<br><br>";

 

echo "<h4>Is {$rij['name']} not what you're looking for?</h4>";       

echo "<a href={$rij['more']}>Click here for more opinions</a>";           

 

// this goes allright

include('../tip.php');       

echo "</div>";       

echo "<!-- end #welcome -->"; 

include('../onderaan3.php'); 

echo "</div>";       

echo "</body>";           

echo "</html>";       

}

?>

 

 

Thanks!

Arjen

Link to comment
Share on other sites

And to be a little bit more specific:

 

Before I said:

 

// this include doesn't work

include('../dbaseincludes/metainclude.php');

 

..That's not totally correct, the include does work for the css, the divs and all the written content but not for the dbase fields.. The include looks like this:

 

<title>{$rij['name']} in {$rij['town']}</title>

<meta http-equiv=content-type content=text/html; charset=iso-8859-1/>

<meta name=description content={$rij['name']} in {$rij['town']}./>

<meta name=robots content=index, follow />

<meta name=author content=vandorsten />

<meta name=design content=vandorsten />

<meta name=copyright content=vandorsten />

<meta name=language content=Dutch />

<meta name=country content=The Netherlands />

<meta name=revisit-after content=7 />

<meta name=keywords content={$rij['name']},{$rij['town']}/>

<link href=/default.css rel=stylesheet type=text/css />

</head>

<body>

<div id=logo>

</div>

<div id=page>

<div id=content>

<div id=welcome>

 

 

Link to comment
Share on other sites

First of all: add the while inside the if ($result ..) otherwise your while will execute even if your if failed. You can even extend to make sure there is something to loop over.

 

$result = mysql_query($query);
if ($result && mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
        ..
    }
}

 

Second:

 

$query = 'SELECT * FROM affiliates WHERE id="4"';

 

Implies your result will be one row which makes the while redundant:

 

$result = mysql_query($query);
if ($result && mysql_num_rows($result)) {
    $rij = mysql_fetch_assoc($result);
    
    // this include doesn't work
include('../dbaseincludes/metainclude.php');

// this echo gives the good information but when I try to get it into an include it doesn't work
echo "{$rij['town']}";

// these things I need in 3 different includes
echo "<h4>{$rij['name']}</h4>";
echo "adress: {$rij['adress']}<br>";
echo "website: <a href={$rij['siteUrl']} target=_blank>{$rij['name']}</a>";

echo "<br><br>";
echo "<h4>Opinion</h4>";
echo "<a href={$rij['siteUrl']} target=_blank>Click here for opinions</a>";
echo "<br><br>";

echo "<h4>Is {$rij['name']} not what you're looking for?</h4>";         
echo "<a href={$rij['more']}>Click here for more opinions</a>";           

// this goes allright
include('../tip.php');         
echo "</div>";         
echo "<!-- end #welcome -->";   
include('../onderaan3.php');   
echo "</div>";         
echo "</body>";           
echo "</html>";
}

 

P.S. Groeten vanuit België ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.