OK, I have never ever coded in php or used mysql before but I went out and gota book and did a little fiddling about and I came up with this.

its only half here, I dont know how to do some of the stuff I want to accomplish and I thought I'd be able to get some help from you guys! Basically I want to make a navigation tool yo go through an archive of online comics. I've created a database containing the comic numbers names and I've also added a 'title' that I would like to stick in my header bar.

ok so my databe has id (the comic number) the comic_name is the name of the file (geniously starting at 00001 and working its way up sequentially) and the header is just a varchar variable with 256 characters.

This basically will load up the latest comic and set up use for the nav buttons

here's is my sketchy code

<?
$conn = mysql_connect("server name" , " "  , " ");
$connect_db = mysql_select_db("comic database", $conn);
$sql = "SELECT MAX('table name'.'id') FROM 'table name';"
$last_comic = mysql_query($sql,$conn);
$comic = $last_comic

if($comic = 1){
$previous_comic = 1;
} else{
$previous_comic = $comic - 1;
}

if($comic = $last_comic){
$next_comic = $comic;
} else {
$next_comic = $comic + 1;
}
?>

Basically this will set up variables for the most recent comic, the curent comic, the previous comic and the next comic.

To actually USE th comic number (aka the id number from the database)

<?
$sql = "SELECT 'table name'.* FROM 'table name'
WHERE 'table name'.'id' = '$comic'
$issue = mysql_query($sql, $conn);
?>

That will create a variable array thing called $issue which I would them implement where

$issue[0] is the id number/$comic value
$issue[1] is the sequential 5 digit comic/blog name (00001.gif and 00001.txt relatively
$issue[2] is the name of the comic I wish to place in the title in the head of the html document

NOW...here is what I need help with.

A) now that I have variables relating to previous next last (and obviously first would be $comic = 1) how do I use this information to make html links to these comics? I have buttons all draw out and all that jazz, but I'm not sure what to type for the link...would it just be
www.mysite.com/filename.php?comic=$next_comic
or would it be more complicated than that?

😎 where do I need to place my php script so that the variable $issue[2] (what I want to place as the title) can actualyl be used in the head portion of the html document? every example in my php book places the connection/query in the body of the html doc but wouldnt that be to late to them put something in the head? clarification or instructions aroudn this would be nice, otherwise it'll jsut be a feature I'll drop or manipulate to lsomething that works.

THANKS!!! I'll continue updating this thread with any other problems that arrise as I build my site.

nEmo

    This might be helpful to you in making your LINKS:

    // connect to Mysql
    $mysql = mysql_connect('localhost', 'username', 'password');
    
    // select specific DB
    $db = mysql_select_db('database_name', $mysql);
    
    // query string
    $query = "SELECT MAX(`id`) FROM `table_name`";
    
    // execute query
    $result = $last_comic_id = mysql_query($query, $mysql);
    
    // if the comicID is not set
    if(!isset($_GET['cid']) || !in_array($_GET['cid'], range(1, $last_comic_id)))
    {
    	$comic = $last_comic_id;
    	$next_comic = false;
    	if($last_comic_id == 1) $previous_comic = false;
    	else $previous_comic = $comic - 1;
    }
    
    // else the comicID is set
    else
    {
    	$comic = $_GET['cid'];
    	if($comic == $last_comic_id) $next_comic = false;
    	else $next_comic = $comic + 1;
    	if($comic == 1) $previous_comic = false;
    	else $previous_comic = $comic - 1;
    }
    
    /* LINKS */
    if($next_comic) $next = '<a href="?cid=' . $next_comic . '">Next</a>';
    else $next = 'next';
    
    if($previous_comic) $previous = '<a href="?cid=' . $previous_comic . '">Previous</a>';
    else $previous = 'previous';
    
    ?>
    

      You can construct a page like this:

      <?PHP
      //Connect to database, run query, assign result to array $issue[] etc etc
      ?>
      <html><head>
      <title><?PHP echo $issue[2]; ?></title><head><body>
      <a href="www.mysite.com/filename.php?comic=<?PHP echo $next_comic; ?>">
      My Link</a>

      Hope this points you in the right direction
      Blu

        ok I'm geting a Parse error: syntax error, unexpected T_STRING in /hosted/subs/ulmb.com/a/n/andrew/public_html/testnav.php on line 47

        here are lines 35 - 52

        /* LINKS */ 
        if($next_comic) $next = '<a href="?cid=' . $next_comic . '">Next</a>'; 
        else $next = 'next'; 
        
        if($previous_comic) $previous = '<a href="?cid=' . $previous_comic . '">Previous</a>'; 
        else $previous = 'previous'; 
        
        $sql = "SELECT 'arcnum'.* FROM 'arcnum'
        WHERE 'arcnum'.'id' = '$comic'
        $issue = mysql_query($sql, $conn);
        ?>
        
        <html xmlns= "http://www.w3.org/1999/xhtml" >
        	<head>
        		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
        		<meta name="generator" content="Adobe GoLive" />
        		<title>Andrew Comics: <?PHP echo $issue[2] ?></title>
        		<style type="text/css" media="screen"><!--
        

        this would put line 47 as

        <html xmlns= "http://www.w3.org/1999/xhtml" >

        so the syntax error is probably th eline before it (or so my book says) but that would put the error in the line

        ?>[CODE]
        
        I'm totally lost at the moment, I was just trying to test out Rodney H's AMAZING work that he did with my original scripting.  Basically I pulle dup my blank template page and just put a single image file in it with the link using the php script, checking if it will actually access my database and pull up the number 00001 (I only have one comic at the moment to test with, the rest aren't on the server yet).
        
        anyways, I'm not even sure what this error means so....help would be AMAZING.  once I get the syntax stuff out of the way I'll test to see if the code does exactly what I want and then work out the kinks.
        
        thanks again,
        nEmo

          NEvermind!! I was missing a ", it slipped by me.

          here's the NEW problem.

          I've published my php onto my server, but after punching in the address, the page doesnt load? could this have to do with the coding/file save/database error or somethign like that or is my web provider in need of a beating?

          nEmo

            There might be another PARSE error somewhere.

            Are you sure you got them all?

            I see a missing semi-colon (";") in your script.

            Usually production servers will have error reporting switched to OFF for security. Most de-bugging should be done during DEVELOPMENT, and not on the live site...

              I already caught the missing ;

              the site actualyl does load, the problem is now connecting. At first the reason why it took so long was an incorrect server name....

              now it connects with good speed, but returns the following at the top of the page

              Warning: mysql_connect() [function.mysql-connect]: Access denied for user '454_comics'@'unlimitedmb.com' (using password: YES) in /hosted/subs/ulmb.com/a/n/andrew/public_html/testnav.php on line 5

              Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /hosted/subs/ulmb.com/a/n/andrew/public_html/testnav.php on line 8

              Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /hosted/subs/ulmb.com/a/n/andrew/public_html/testnav.php on line 14

              Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /hosted/subs/ulmb.com/a/n/andrew/public_html/testnav.php on line 43

              So basically its not connecting and threrefor none of the queries can be carried out.

              can someone give me an example of what EXACTLY needs to be written for the mysql_connect command?

              EDIT:
              you'd probably want to see the code to connect wouldn't you?

              // connect to Mysql 
              $mysql = mysql_connect('ftp.ulmb.com', '454_comics', 'my password'); 
              
              // select specific DB 
              $db = mysql_select_db('454_comics', $mysql); 
              
              // query string 
              $query = "SELECT MAX(`id`) FROM `arcnum`"; 
              
              // execute query 
              $result = $last_comic_id = mysql_query($query, $mysql); 

              I'm assuming the server is the same place I host my site? I dont know what else it would be. my username defaults as the same name as the database (so in my case 454_comics) and my password (this web hosting provider forces you to have one) is correct, I know tHAT much.

              I have a feeling I'm connecting to the wrong server...where would I find out the server name from within phpmyadmin, since thats what this site uses?

              ANOTHER EDIT!!

              I fixed it, It WAS the server name as I thought. now I'm left with just one error:

              Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /hosted/subs/ulmb.com/a/n/andrew/public_html/testnav.php on line 43

              so its back to the source code!

              /* LINKS */ 
              if($next_comic) $next = '<a href="?cid=' . $next_comic . '">Next</a>'; 
              else $next = 'next'; 
              
              if($previous_comic) $previous = '<a href="?cid=' . $previous_comic . '">Previous</a>'; 
              else $previous = 'previous'; 
              
              $sql = "SELECT 'arcnum'.* FROM 'arcnum' WHERE 'arcnum'.'id' = '$comic'";
              $issue = mysql_query($sql, $conn);
              ?>

              so line 43 would be

              $issue = mysql_query($sql, $conn);

              so what could this error mean and how would I fix it?

              thanks AGAIN!

              nEmo

                ok, so only the second query is giving me a problem, the first returns no error. so what do I do? check if the first query is actually doing what I want it to do!

                following the code

                // execute query 
                $result = $last_comic_id = mysql_query($query, $mysql); 

                I printed the value for $result and $last_comic_id, and they SHOULD be the same....which they are

                BUT they AREN'T what I expected. My database at the moment only has 1 entry with id 1...so the result should have been '1'

                instead I got

                Resource id #3

                wtf? thats not even a number! CONFUSED!!

                ALSO...with the second query, I thought it may have been an error caused by the first query returning the wrong value (which is appaerntly is) so instead of

                $sql = "SELECT 'arcnum'.* FROM 'arcnum' WHERE 'arcnum'.'id' = '$comic'"; 
                $issue = mysql_query($sql, $conn);

                I changed $comic to simply be 1, automatically always bringing me the values for the first issue of my comic...BUT I still get the same error as before, meaning there must be something wrong with my command to query or my connection to the database. anyone have any bright ideas?

                nEmo

                  Write a Reply...