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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible with PHP

Status
Not open for further replies.

sd0t1

IS-IT--Management
Mar 14, 2007
131
US
I have a page loaded into the database called showthumbs. On the page is a SQL statement that selects all thumbnails where category_id is $whatever. The page is named in the database "showthumbs". When you click on a link the link sends to the index page the name of the page to load (showthumbs)in the center and it sends a category_id, which is supposed to load the correct thumbnails for that category. However once the page content is loaded from the SQL section I think I need to reload that page to perform the SQL statement with the categoryID being the where clause. I hope this is making sense. Here is some code. I know this has to be possible.
My goal is to create a site that has all the page content stored in the database and I just call each page I need.

THIS IS THE CONTENT THAT IS LOADED INTO THE DATABASE, IT'S CALLED SHOWTHUMBS.
<?php require_once('Connections/testconnect.php');?>
<?php
//***********************************************************************************************
// Select from photo_table where photo_category = photo_category all thumbs 25 at a time.
//***********************************************************************************************
$maxRows_thumbscontent = 25;
$pageNum_thumbscontent = 0;
if (isset($_GET['pageNum_thumbscontent'])) {
$pageNum_thumbscontent = $_GET['pageNum_thumbscontent'];
}
$startRow_thumbscontent = $pageNum_thumbscontent * $maxRows_thumbscontent;

$colname_thumbscontent = "-1";
if (isset($_GET['photo_category'])) {
$colname_thumbscontent = (get_magic_quotes_gpc()) ? $_GET['photo_category'] : addslashes($_GET['photo_category']);
}
mysql_select_db($database_test, $test);
$query_thumbscontent = sprintf("SELECT * FROM photo_table WHERE photo_category = %s", $colname_thumbscontent);
$query_limit_thumbscontent = sprintf("%s LIMIT %d, %d", $query_thumbscontent, $startRow_thumbscontent, $maxRows_thumbscontent);
$thumbscontent = mysql_query($query_limit_thumbscontent, $test) or die(mysql_error());
$row_thumbscontent = mysql_fetch_assoc($thumbscontent);

if (isset($_GET['totalRows_thumbscontent'])) {
$totalRows_thumbscontent = $_GET['totalRows_thumbscontent'];
} else {
$all_thumbscontent = mysql_query($query_thumbscontent);
$totalRows_thumbscontent = mysql_num_rows($all_thumbscontent);
}
$totalPages_thumbscontent = ceil($totalRows_thumbscontent/$maxRows_thumbscontent)-1;
?>

<form name="form1" method="post" action="">
<table width="547" border="0">

<?php do { ?>
<tr>
<td width="36"><input name="thumbselect" type="radio" value="<?php echo $row_thumbscontent['photo_category']; ?>" onClick="document.forms['form1'].submit();"/></td>
<td width="209"><?php echo $row_thumbscontent['photo_thumb_name']; ?></td>
<td width="226"><?php echo $row_thumbscontent['photo_desc']; ?></td>
</tr>
<?php } while ($row_thumbscontent = mysql_fetch_assoc($thumbscontent)); ?>
</table>
</form>

HERE IS WHAT I USE TO CALL IT OUT OF THE DATABASE.

A link called index.php?photo_category=<?php echo $page_name;?>&show_cat=showthumbs

IT IS PULLING THE RADIO BUTTON ONTO THE INDEX SCREEN BUT BOTH VARIABLES ARE BLANK.
....Can someone give me some other suggestions or help me make this work.

Thanks in advance to everyone. And special thanks to those whov'e helped me before.
 
sd0t1--

I don't want to make you more frustrated, but it appears you haven't had any replies because your question is a bit unclear. What exactly is it that you are trying to achieve in PHP?

-apeace
 
Sorry for being unclear.

In my Mysql database is a table called "HTML_content." It has a 4 fields, id, page_name, page_content, dateupdated. What I'm doing is creating pages as normal and then uploading the name and the html content into the database. Then when I need that page i just call it from inside the ONLY page in the website which is index.php and place it in the center frame.
My goal is to have just 1 page to the site and just change the center frame of the page to load all the different dynamic content. I've loaded all the content into the MySQL database and so each different content is really just a sql select statement.
On the index.php page i have to make some "IF" statements to know what sql select statement to use for each link you click.

I sure hope that helps.
 
instead of using IFs, consider using a switch{} construct. take a look in the manual for examples.

the code above looks strangely unsuited for the task at hand. almost as if you had taken the code from somebody's recipe on dynamic paging or records (which is not the same as displaying dynamic content).

at an abstracted level your code should look something like this

Code:
<?
$defaultpageID = XXX; //complete as appropriate
$id = (isset($_GET['page_number'])) ? mysql_escape_string(trim($_GET['page_number'])) : $defaultpageID;
$result = mysql_query("select page_name, page_content from tablename where page_number = '$id'") or die (mysql_error());
if (mysql_num_rows($result) > 0) {
 $row = mysql_fetch_assoc($result);
} else {die ("no content found");
echo <<<HTML
<html>
<head>
<title>{$row['page_name']}</title>
</head>
<body>
{$row['page_content']}
</body>
</html>
HTML;
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top