Page 1 of 1

Tutorial System - What I Need/What I Know

Posted: Sun Jan 22, 2006 11:15 pm
by xEzMikex
Allright my goal is to make a tutorial system with the following features.

-Add tutorials(80%)
-Delete tutorials(80%)
-Automatically add tutorial names to the list(40%)
-Have a count of how many tutorials there is beside the subject name(5%)

The percentage beside them is how sure I am that I CAN do the tast.

Details - I know how to add information and display it on a single page, Well I would like to create some sort of code so when I add tutorials to the database I can display it by a link, Somthing like this "www.test.com/tutorials?php=1" I want it so this will show the tutorial on the page with my template.

This is the code im working with so far.

Code: Select all

<?php
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$query = "SELECT * FROM phptuts ORDER BY `id` DESC";

// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// see if any rows were returned
if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another
    while($row = mysql_fetch_assoc($result)) {

	    echo "<b>Tutorial By : </b>"."<b>".$row['name']."</b><br>";
        echo "<b>Date : </b><b>".$row['date']."</b><br><br>";
		echo $row['content']."<br><br>";
    }
}
else {
    echo "No rows found!";
}

// free result set memory
mysql_free_result($result);

// close connection
mysql_close($connection);
?>

Posted: Mon Jan 23, 2006 3:48 am
by php3ch0
First of all you need to add a link to the page that will display the results.

Change the following code to:

Code: Select all

echo "<a href = 'view_tutorial.php?id=".$row['id']."'><b>Tutorial By : </b>"."<b>".$row['name']."</b></a><br>"; 
        echo "<b>Date : </b><b>".$row['date']."</b><br><br>"; 
        echo $row['content']."<br><br>";
This will create a link to the next page (view_tutorial.php?id=1 for example)

next create a new page called view_tutorial.php and adapt your sql query like this:

Code: Select all

<?php 
// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 
mysql_select_db($db) or die ("Unable to select database!"); 

$id = $_GET['id'];

// create query 
$query = "SELECT * FROM phptuts where id = '$id'"; 



        echo "<b>Tutorial By : </b>"."<b>".$row['name']."</b><br>"; 
        echo "<b>Date : </b><b>".$row['date']."</b><br><br>"; 
        echo $row['content']."<br><br>"; 



// free result set memory 
mysql_free_result($result); 

// close connection 
mysql_close($connection); 
?>
You would also want to consider validating the input as users could add anything to the URL e.g view_tutoral.php?id=something else

You would also need to add something if the result is empty.

Posted: Mon Jan 23, 2006 12:45 pm
by xEzMikex
Thanks alot, I undestand that and am going to try it now. When I am done I will post my results.

Posted: Mon Jan 23, 2006 12:59 pm
by xEzMikex
Allright well I ran into some problems. I got the link and all but when I click the link it doesnt work.

EDIT

Nevermind the file name was spel wrong... But now there is no data in the feilds like "Posted By:" and "Date:" its empty beside them.

Posted: Mon Jan 23, 2006 1:21 pm
by php3ch0
sorry I forgot to execute the query please add this code back in

Code: Select all

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
$row = mysql_fetch_assoc($result);

        echo "<b>Tutorial By : </b>"."<b>".$row['name']."</b><br>"; 
        echo "<b>Date : </b><b>".$row['date']."</b><br><br>"; 
        echo $row['content']."<br><br>";

Posted: Mon Jan 23, 2006 1:35 pm
by xEzMikex
Thank you so much! I need to fix it up a little bit and add some more feilds but soon as it is done and on the net I will link you, Thank you so much.

Posted: Mon Jan 23, 2006 2:04 pm
by php3ch0
No Probs. Anything to help