Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query String

Status
Not open for further replies.

magicandmight

IS-IT--Management
Aug 27, 2004
77
US
I have successfully integrated a query string into my code. I almost have my page done except for make a code to pull in another page that is dependant on the string. Here is my code:
<? $server_side_mycoolvariable = ''; if (isset($_GET['category'])) $server_side_mycoolvariable = $_GET['category'];
include("mbconnect1.php");
$query = "SELECT * FROM category WHERE category LIKE '%$server_side_mycoolvariable%'";
include("catadsearch.php"); ?>

-- code on catadsearch --

<?php
$result = MYSQL_QUERY($query);
if (!$result) print ("There are no members in this category.<br>");
/* Determine the number of records returned */
$result = mysql_query($query) or exit('Please make another selection.');
$number = mysql_num_rows($result);
$i=0;
while($rows=mysql_fetch_array($result,MYSQL_ASSOC))
{
if (!empty($rows['link']))
echo '<?php require($DOCUMENT_ROOT . "/catext/',$rows['link'],'");?>';
//same for all the field...
$i++;
}

/* Close the database connection */
MYSQL_CLOSE();
?>


This does not show up on the page echo does not show up on the display page, but it does show up in pink on the page source that I get from mozilla, with the link being correct. Any idea on why its not going?
 
i'm pretty sure that this line is not what you intend.
Code:
echo '<?php require($DOCUMENT_ROOT . "/catext/',$rows['link'],'");?>';

should it be:
Code:
require($DOCUMENT_ROOT . "/catext/{$rows['link']}");

or perhaps
Code:
echo file_get_contents ($DOCUMENT_ROOT . "/catext/{$rows['link']}");

i would use the first if there was code in the file that i wanted to be evaluated by php and the second if i wanted to do some manipulations on the file contents before echo'ing it and/or wanted it in a string.
 
The first one got it once I realized you meant to leave the echo off.
 
supposed" is a difficult word here. the functions "require" and "include" (and their variants) cause php to *evaluate* the relevant file. this means that php code (outside of functions) is run and html is output to the browser.

for example if an included file contained purely functions then nothing would be output to the browser but all those functions would be available to the code in the calling page.

conversely, if an included page contains just html then this will be output to the browser at the point of the require/include. if you want more control over the output of an html file then use the file_get_contents() function i mentioned above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top