Jump to content

A better way to do this?


doddsey_65

Recommended Posts

Hi, I have a rating system in place on my site. The problem is i have a section called tutorials, which pulls all the results from the database. I would then click on a result to bring that tutorial up. I have gone with this because the rating system depends on things being on different pages. But at the minute i have 50 tutorials and loads more to input. I dont want to have to create a seperate page for every tutorial but the way my rating system is, i would have to. is there anyway to display the tutorial once clicked, without having to create a page for each one and for the rating system to work within this setup.

 

Heres an example of my current setup

 

HOME>>TUTORIALS>>TUTORIAL1

              list of tuts      the tut vid

 

 

Link to comment
Share on other sites

Okay say i have a tutorial named test and the tutorial is by carl.

In my site you would click on tutorials to bring up a list of people who have made tutorials.

You would then click carl to bring up all tutorials by him.

Then you would click on the tutorial named test to bring up the actual tutorial video.

But this means creating a file called test.php within wich resides the code to show the video.

But this also means creating a new .php file for every tutorial which i dont want to do.

So is there anyway to avoid this? Something like pagination?

 

An example of the file structure above

 

home page      tutorial list          listt by carl              actual tutorial vid

Index.php >> tutorials.php >> tutorials.carl.php >> test.php

 

 

forget the mention of the rating system for now, i will get to that later in order to minimise confusion lol.

Link to comment
Share on other sites

But this means creating a file called test.php within wich resides the code to show the video.

But this also means creating a new .php file for every tutorial which i dont want to do.

No it doesn't. You have 1 single file that displays any tutorial. You could have another file that displays any video. The data is requested via a database query from what are known as url parameters i.e

links to 2 tutorials

tutorial.php?id=123

tutorial.php?id=127856

 

Do you think that there is a new php page created on this forum whenever a new topic is posted. Just look at the url. We remain on index.php throughout and the post is obtained through the url parameters.

 

Link to comment
Share on other sites

how would i achieve this in the code then? i should mention that all of my tutorials are embedded from youtube

I can't lay down the whole code for your website but you must have a database structure containing your tutorials relating to the users who submitted them? The embed code should be in the database also against the tutorial so you can display the video. If a user clicks on Carls tutorials, lets say he is user id 123 I would run a query to get his tutorials

/tutorials.php?userId=123

<?php
$result = mysql_query("SELECT id, title FROM tutorials WHERE userId='".mysql_real_escape_string($_GET['userId'])."'");
// display the tutorials
while($row = mysql_fetch_object($result)) {
print "<a href='/tutorial.php?id=".$row->id."'>".$row->title."</a><br />";	
}
?>

This would display links to all of carls tutorials. The file is tutorial.php and I pass over the id of the tutorial. I can then get the required tutorial from this paramater. Much the same as I have done above

Link to comment
Share on other sites

Okay here is the current layout of tutorials.derricksesson.php

I tried your code but couldnt get it to work.

 


<?php 

ob_start();
include('header.php'); 
include('db.php');
    $db=mysql_connect($db_host,$db_user,$db_pass)
or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db($db_name,$db);

$pagenum = $_GET['pagenum'];

if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 

//Here we count the number of results 
//Edit $data to be your query 
$data = mysql_query("SELECT * FROM tutorials WHERE username='cganim8or'") or die(mysql_error()); 
$rows = mysql_num_rows($data); 

//This is the number of results displayed per page 
$page_rows = 3; 

//This tells us the page number of our last page 
$last = ceil($rows/$page_rows); 

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

//This sets the range to display in our query 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

echo '<div id="page">';
echo '<div id="content"><br />';
echo '<h2 class="title">Tutorials By Derrick Sesson</h2><br />';





$result = mysql_query("SELECT fullname, name FROM tutorials WHERE username='cganim8or'") or die(mysql_error());
while($row = mysql_fetch_object($result)) {	
print "<a href='/tutorials.php?id=".$row->fullname."'>".$row->name."</a><br />";	
}







echo '<br><br><br></div>';
echo '</div>';
} 

echo " Page $pagenum of $last <p>";

if ($pagenum == 1) 
{
} 
else 
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
} 

//just a spacer
echo " ---- ";

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
} 


echo '</div>';

include('footer.php');
ob_flush(); 
?>

 

The rows in the tutorials table are:

ID - tutorial id not userid

name - name of tutorial

description - of tutorial

username - of tutorial provider

fullname - of tutorial provider

link - link to tutorial

path - path the the image thumbnail

 

hopefullyyou will be able to show me how i would get it to display the tutorial once the user clicks the tutorial they want.

Link to comment
Share on other sites

Ok i have gotten it to display the tutorials(even though the pagination isnt working), but how do i go about creating the next file that will display the tutorial they clicked on? instead of id i have gone for username since id in my table is the tutorial id and not the userid.

 

when i click on a tutorial by 'carl' it takes me to tutorials.php?username=test

so how would i make that page?

When i click the link i just get sent back to the previous page(the list of tutorial publishers)

Link to comment
Share on other sites

post? im not using the post variable al i want is when you click on a link in tutorials.php it wil take you to tutorials.php?username=whatever, within which resides the video. so how would i get the video of the clicked tutorial to display under tht url?

Link to comment
Share on other sites

Okay i will try to describe things better:

a user is given a list of tutorials on the page tutorials.php.

when a user clicks a tutorial name they are taken to the tutorial video which will appear on tutorials.php?id=1

so how do i set up the page tutorials.php?id=1?

I can get the tutorials in tutorials.php to go to their id pages(tutorials.php?id=) but i dont know how to set up the pages to show the video which is relative to whatever tutorial they click.

Link to comment
Share on other sites

okay im gonna try and explain this one last time in the hope that someone knows what i mean and can help.

 

I list all tutorials by cganim8or

 

$result = mysql_query("SELECT * FROM tutorials WHERE username='cganim8or' $max") or die(mysql_error());
while($row = mysql_fetch_object($result)) {	



echo '<div class="post">';
echo '<p class="meta">' .$row->fullname. ' | ' .$row->name;

echo '<div class="entry">';
echo '<a href=tutorials.php?id='.$row->name.'>'.$row->name.'</a><br />';	
echo '</p>';


echo '<br><br><br></div>';
echo '</div>';
}

 

and as you see when you click on a tutorial by him you aere taken to tutorials.php?id=nameoftutorial.

 

How do i make that page? How do i display the tutorial video on that page? I am assuming i put the code in this same file but what code? i dont even know where to start.

 

 

In my code fullname refers to the full name of the tutorial artist

name refers to the name of the tutorial( i cant use id cos the id is for the id of the tutorial not the user

 

So, when a user clicks a tutorial they are taken to the video and the url will read tutorials.php?id=nameoftutorial

this is so i dont have to make a single page for every tutorial that i have. All i would need on this page is the youtube embed code.

 

So can anyone help? Im really struggling. And even if this is easy then pplease say so and try to help.

Link to comment
Share on other sites

("SELECT * FROM tutorials WHERE username='cganim8or' $max")

The username will be in the superglobals array sent through the url. i.e

("SELECT * FROM tutorials WHERE username='".mysql_real_escape_string($_GET['username'])."' $max") 

The reason you are duplicating so many pages is that you have hard coded the database queries. This is incorrect for dynamic websites. If you had read the tutorial from the link I posted it explains how to query data based on paramaters sent through the url. This is what applies to you. Get a better understanding of how dynamic sites work.

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.