Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Hello, I'm quite frustrated

    I'm brand new here and I really don't know where I would go about asking this, so I'll just ask here.

    Some background: Last semister in my database class, we were asked to do this bookstore website using a database (obviously). Think amazon.com, on a smaller scale. We didn't need to have it actually online, just run it on our machines. Lets just say I didn't do the best on it and I got a lot of help from a friend. It was done in PHP/HTML and mySQL. He set up a file that had functions in it that the other files could call. These other files were NOT in the same folder as the function file.

    Today: A friend and I were put in charge to make a website for the business I work for (it's family owned and operated, I'm the son of the owner). Anywho, I originally wanted to use the small database skills I had learned to do this, but I couldn't figure it out and kind of did it the long, hard-coded way. After a little bit I figured out how to do functions in PHP, but learned that that file needed to be in the same folder as the file calling it, no biggy. This was not a problem because I just wanted to get some visual of a site, not caring if it was the right way of doing it. Well, now that I have a lot of it up, I can slow down and re-examine things. Meaning, as you probably guessed it, I wanted to go back and figure out the whole database thing.

    After talking to my friend, I found the built in database stuff for our server. It's phpMyAdmin 2.11.2.1, if that matters. I created the database, created a table, and put an item in that table. This is for test purposes because I didn't want to just jump in without knowing if was going to work. In the actual webpage file, I put what had been in the file in the school project, namely: (where I put "generic" is not actual name of stuff)

    PHP Code:
    <? include_once ("../../functions.php");

        
    NormalDisplay("generic_table");
    ?>

    Then the file functions.php, I put what was in the school projects functions.php file:
    PHP Code:
    <?

    function Make_Connection()
    {   
    $link mysql_connect('mysql."generic".com ''''');
        if(!
    $link)
        {   die(
    "Error: Could not connect -> ".mysql_error());
        }
        
    $result mysql_select_db("generic_database" ,$link);
        if(!
    $result)
        {   die(
    "Error: Could not find Database -> ".mysql_error());
        }
        return 
    $result;
    }


    function 
    NormalDisplay($TableName)
    {
        
    $connect Make_Connection();
        
    $result mysql_query("SELECT * FROM ".$TableName);
        
        
        
    $Type mysql_query("SELECT Type FROM ".$TableName);
        
    $Category mysql_query("SELECT Category FROM ".$TableName);
        
    $Code mysql_query("SELECT Code FROM ".$TableName);
        
    $Name mysql_query("SELECT Name FROM ".$TableName);
        
    $Price mysql_query("SELECT Price FROM ".$TableName);
        
    $Item mysql_query("SELECT Item FROM ".$TableName);
        
    $NC mysql_query("SELECT NC FROM ".$TableName);

             if(!
    $result)
             {  die(
    "Error: Could not find Table -> ".mysql_error());
             }
        
    ?>
        
        <table border = "1" valign = "top" align = "center" width = "90%">
            <tr>
                <th colspan = "5"> <? print $TableName ?> </th>
            </tr>
            <?
            
    for($i 0;$i mysql_num_fields($result);$i++)
            {   
    $header mysql_field_name($result,$i);
                if(
    $header != "ID" && $header != "NC" && $header != "Era" && $header != "Color")
                
    ?> <td> <? print $header ?> </td> <?
            
    }
            
    ?>
            </tr>
            <?

            ?>
    </table><?
        $connect
    .mysql_close();
    }

    ?>
    There will be more in the NormalDisplay function, but again, I don't want to rush into something without it working.

    Well, for whatever reason, this is not working, and I don't know why. It's the same general set-up as the school project, except for the fact this one is actually online. How would I go about fixing it?

    Many thanks to all in advance.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    have you checked you have some test data in? ont he face of it the code looks ok
    one thing I would suggest is that you always put something in to check for no data returned.. you don't need to display it to the user, you could send an email or record the fault in a faults/errors table in the live system

    its possible to find the table, but no rows, so I'd suggest you have a look at the php.net site and look at the other MySQL functions such as num rows returned.

    mind you I don't understand why you have a whole series of single SQL statements
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2008
    Posts
    2
    First off, it doesn't even look like it's getting to the function. There is a piece of data, but with the code I have there, it isn't even printing any of that out. I added a html line of code to that function and it didn't do that, so I believe that it's not getting to the function. No idea why it isn't.

    Why do I have:

    PHP Code:
    $Type mysql_query("SELECT Type FROM ".$TableName);
        
    $Category mysql_query("SELECT Category FROM ".$TableName);
        
    $Code mysql_query("SELECT Code FROM ".$TableName);
        
    $Name mysql_query("SELECT Name FROM ".$TableName);
        
    $Price mysql_query("SELECT Price FROM ".$TableName);
        
    $Item mysql_query("SELECT Item FROM ".$TableName);
        
    $NC mysql_query("SELECT NC FROM ".$TableName); 
    When I have this also:

    PHP Code:
    $result mysql_query("SELECT * FROM ".$TableName); 
    Well, I was under the impression that $result was like a 2D array/vecter. And I could traverse it like one as well. But looking at the code that I had from my previous venture into databases:

    PHP Code:
    while($row = mysql_fetch_array($result))
            {   ?><tr><?
                
    for($i 0;$i mysql_num_fields($result);$i++)
                {   
    $header mysql_field_name($result,$i);
                if(
    $header == "ID")
                    {   
    ?><td><a href=<? print "\"Generic_File.php?tablename=".$TableName." &id=".$row[$header]." \" " ?> > <? print $row[$header?></a></td><?
                    
    }
                else if(
    $header == "Price")
                    {   
    ?><td>$<? print $row[$header?></td><?
                    
    }
                else
                    {   
    ?><td><? print $row[$header?></td><?
                    
    }
                }
            }
    It did not look like that was the case, namely the order that they information is in the field was not the exact order of when I needed things. In that string of select lines, the $Category and $Type ones were for part of a displaying an image (I.E. ../../$Category/$Type/Image_Name.jpeg) and I wasn't sure how I would do that with the way it was setup with just the $result way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •