Jump to content

How to create multiple pages from one php script


callisto11

Recommended Posts

Hi everyone,

 

below is a copy of my script, that uploads pictures of sports from my database onto my website.this based on the catergory, i want to be able to modify this script to also upload pictures from all the different catergories that i have created on their individual pages, without me having to write same code over again and over again for each catergory. At the moment theres six different catergory in my table called general cartoons. (I know i might not be making sense, but its hard to explain something without the person seeing it,if you understand what I mean, Im in desperate need of sorting this out!) Im very new to using php and my sql and I've search everywhere on the web to help me with this problem. ???

                                                                                              Thank you

 

 

 

 

<?php

      session_start();

 

 

 

require "connect.php";

$query = "select * from general_cartoon where subject_type='sport'";

$result = @mysql_query($query, $connection) or die ( "Unable to perform query.<br/>$query<br/>".mysql_error());

//require "shoppingcart.php";

 

?>

 

 

<html>

<body>

<center>

<h1><img src="logo.jpg" align=center  width="600" height="200"></h1>

</center>

 

<html>

<body>

<table border=0 width=900>

<tr>

<td valign=top width=200>

<p><a href="homepage.php">ARTIST</a></p>

<p><a href="gallery.php">GALLERY</a></p>

<p><a href="">CONTACT</a></p>

<p><a href="customerlogin.php">SIGN IN/ SIGN-UP</a></p>

<p><a href="">FORMAT/PRICE</a></p>

<p><a href="shoppingcart.php">VIEW SHOPPING CART</a></p>

</td>

 

 

<td valign=top width=700><p>

<ol type="A">

<font face="scans-serif" color="Purple"  size="+5" align="right" >SPORT

</p>

</ol>

 

</td>

</tr>

</table>

 

 

</body>

</html>

 

 

<html>

<body>

<center>

<table border="6">

  <tr>

<th >TITLE</th>

<th >CARTOON</th>

<th> </th>

</tr>

 

 

<?php

 

while($row= mysql_fetch_array($result))

 

{

echo "<tr>";

echo "<td>".$row['title']."</td>";

echo "<td><img src=\"pics/".$row['location_of_cartoon']."\"></td>" ; ?>

 

 

<td><a href="addtoshoppingcart.php?cartoon_id=<?php echo $row['cartoon_id']; ?>&title=<?php echo $row['title']; ?>"> [ADD] </a></td></tr>

<?php

}

 

?>

 

 

 

</table>

<center>

 

 

Link to comment
Share on other sites

Not to sure If I understand correctly.. but ill give it a go.. Rather then 6 scripts of the same nature.. you could introduce a variable to the script that would define the category.. so pending on the variable the script would upload it to the appropriate section.

 

your code:

$query = "select * from general_cartoon where subject_type='sport'";
$result = @mysql_query($query, $connection) or die ( "Unable to perform query.
$query

 

Alternative:

$query = "select * from general_cartoon where subject_type='$category_type'";
$result = @mysql_query($query, $connection) or die ( "Unable to perform query.
$query

 

There is still modifications you will have to make to the over all page/script. But its possible to do what you want.

You can define the "$category_type" through a var passed in a URL, or via a form, or multiple other ways.. but mostly depends on how the rest of your site works.

 

example of link would be: www.blah.com/page.php?cat=sport but again depending on the rest of the structure is how you would want to lay that out.. Couldn't really say as I don't know exactly how the site works thats in question..

Link to comment
Share on other sites

THE Field is not actually called catergory_type, its called subject_type. I've tried changing it and its not working. I don't know what im doing wrong or is the whole script that needs modifying. So what Im saying is suject type is alway different. In my database the pictures are saved based on their subject type. So On my website I want all subject types pictures to  displayed on different pages using one script. (Im soooooo confused on how to do it!)

Link to comment
Share on other sites

$category_type i was just using for sample sake  ;D

 

If I am understanding you right then yes, as previously state the whole script may need some alterations in order to work accordingly with what you want. Unfortunately what you want done is going to need a bit of coding on top of whats there to work the way you want it to, theres no escape from that. Ultimately (not my style) but a page for every subject containing the same code but for that subject.. Or.. altering the coder over all and possibly a few elements else where pending on your layout to make one page work dynamically for each subject.

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.