SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    String problems!!

    This doesnt work.

    The top half executes fine and i can click on a link and the info in my database is shown, but when i try to make that info into a link and set it as another variable it doesnt work

    Heres the code:

    PHP Code:
      <?php
      
      
    //Start the check to see if the link has been clicked
      
      
    if ($_GET['Category'] == "")
      { 
      
    ?><h5><center><strong>Please make your selection!</strong></center></h5><?php //Link hasnt been clicked so message is diplayed, else display error message
      
    }

    //The link has been clicked so:  
    else
    {
        
    $Connect mysql_connect('localhost''tutorialadmin''ffviii6885') or die("Could not connect: ".mysql_error()); // connect to the database, else display error message
        
        
    mysql_select_db('tutorials'$Connect) or die("Couldn't select database: ".mysql_error()); // Select the database to use
        
        
    $Cat '\'' mysql_real_escape_string($_GET['Category']) . '\''// Assigning the GET as a variable and doing a check on it to escape special characters so we can use it in mysql
        
        
    $Sql 'SELECT'
            
    .    ' TutName, Author, UserRating, EditorRating, TimesViewed, DateAdded, ScriptCat, ScriptType, Link, Description' // Select which columns we want to query with
            
    .    ' FROM'
            
    .    ' tutorials' // Select the table to get the columns from
            
    .    ' WHERE'
            
    .    ' ScriptType = ' $Cat // Make sure only the rows for the selected category are shown
            
    ;
            
        
    $Result mysql_query($Sql) or die ('Failed to execute ' $Sql ' due to ' mysql_error()); // Start the query for the database, else display error message
        
        
    if (mysql_num_rows($Result)) // Asking the database whether there are any rows that match the criteria, if so:
        
    {
            while (
    $MyRow mysql_fetch_array($Result)) // Start a loop to check the result and start displaying them
            
    {
             
    ?>
            <table width="100%" height="30px">
            <td><h5><strong><a href="/tutorials.php?viewtutorials=true"><? echo $MyRow['ScriptCat'?></a></strong></h5></td> <?php // Display the result from the databse ina table and also make them links so that we can click on them to select the tutorials ?>
            </table>
            
            <?php
            
            $ViewTutorials 
    $_GET['viewtutorials'];
            
        } 
    //end the if statement

            
    // end the while statement
        
        
        
    else
        {
        
    ?>
        <h5><center><strong>We do not have any tutorials in that category at this time!</strong></center></h5>
        <?php
        
    }


    if (
    $ViewTutorials == TRUE)
    {
    echo 
    "It Worked";
    }


    // Ending the first else statement
    ?>
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So this...
    PHP Code:
    <a href="/tutorials.php?viewtutorials=true"><? echo $MyRow['ScriptCat'?></a>
    ...doesn't work? I don't know what you mean.

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The link displays fine but i want an if statement to handle a query when the link is clicked, this is the part that im having a problem with:

    PHP Code:
    <a href="/tutorials.php?viewtutorials=true"><? echo $MyRow['ScriptCat'?></a></strong></h5></td> <?php // Display the result from the databse ina table and also make them links so that we can click on them to select the tutorials ?>
            </table>
            
            <?php
            
            $ViewTutorials 
    $_GET['viewtutorials'];
            
        } 
    //end the if statement

            
    // end the while statement
        
        
        
    else
        {
        
    ?>
        <h5><center><strong>We do not have any tutorials in that category at this time!</strong></center></h5>
        <?php
        
    }


    if (
    $ViewTutorials == TRUE)
    {
    echo 
    "It Worked";
    }


    // Ending the first else statement
    ?>
    When the link is clicked, its should be handled by the GET method and then changed toa variable, when that variable is created "It Worked" is printed on the screen, in theory that should work but it doesnt!!
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  4. #4
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    Kelowna, BC
    Posts
    202
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would check to see whether or not $ViewTutorials is empty and also reinitialize the value at the beginning of the loop.

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im sorry but i dont understand what you mean
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    It might be because you are trying to use a reserved word (TRUE). change your link to
    Code:
    ="/tutorials.php?viewtutorials=yes
    and change your $_GET settings
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2 things, what do u mean cahnge my $_GET settings and alos how do i give rep for you
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    change...
    PHP Code:
    if ($ViewTutorials == 'yes'

    echo 
    "It Worked"

    My mistake, meant change the if statement!!

    As for rep, there should be a set of scales next to the online status, click it!
    (if there isn't, goto your profile and activate the rep settings)

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, i have found out what the problem is. The error is in the first part of my code:

    PHP Code:
    if ($_GET['Category'] == "" )
      { 
      ?><h5><center><strong>Please make your selection!</strong></center></h5><?php //Link hasnt been clicked so message is diplayed, else display error message
      
    }
    If a link hasnt been clicked, the value of $_GET['Category'] is blank and therefore displays the error message. When i start the other variable up this one seems to go back to a blank value and therefore displays "Please make your selection"


    So the new problem is to makle this not happen!?!?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Try...
    PHP Code:
    <?php 
       
      
    //Start the check to see if the link has been clicked 
       
      
    if (!isset($_GET['Category'] ))
      { 
     echo 
    "<h5><center><strong>Please make your selection!</strong></center></h5>"//Link hasnt been clicked so message is diplayed, else display error message 
      
    }
    See if it makes a difference!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, well that doesnt seem to work either. Should do by all rights though
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Can I just check what you are trying to do...
    1./ Connect to the database and pull the records that correspond to the link that was clicked.

    2./ display those records in a list and link them to......
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok step by step:

    try this link http://www.webnoob.com/tutorials.php


    Click on a link on the left hand side i.e php

    It then searches the database for tutorial with a ScriptType of PHP

    When the php tutorials are found it looks at the the different categories and lists them (i.e sessions, authentication)

    The user then clicks on the category they want to view (This is as far as i have got)


    And then all the tutorials in that category are displayed.


    Phew!
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    OK, run the code below in a new page!
    PHP Code:
    <?
        $Connect 
    mysql_connect('localhost''tutorialadmin''ffviii6885') or die("Could not connect: ".mysql_error()); // connect to the database, else display error message 
        
    mysql_select_db('tutorials'$Connect) or die("Couldn't select database: ".mysql_error()); // Select the database to use 

    if(!isset($_GET['Categories'])) {
    echo 
    "Please select your category";
    } else {
    $Cat $_GET['Categories'];

        
    $Sql mysql_query("SELECT Tutname, Author, UserRating, EditorRating, TimesViewed, DateAdded, ScriptCat, ScriptType, Link, Description FROM tutorials WHERE ScriptType = '$Cat'") or die(mysql_error()); // Make sure only the rows for the selected category are shown 
        
    $res mysql_fetch_assoc($Sql);
        if(
    mysql_num_rows($Sql) > 0) {
        do { 
    ?>
    <h5><strong><a href="/tutorials.php?viewtutorials=yes"><? echo $res['ScriptCat'?></a></strong></h5>
    <? } while($res mysql_fetch_assoc($Sql)); 
    ?>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #15
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well thanks for the script but still it doesnt seem to have any joy! I dont understand it because it works for the first part but then wont work for the last link!
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    will get back to you tomorrow mate!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well thanks for your help ive added to your rep

    Thanks again!!
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  18. #18
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there

    Will there be more than 1 tutorial in the PHP/Sessions category?

    I need to know this so that we can work out what the query string on the links should be. Once this is defined, we can work out the correct logic required in tutorials.php

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by swdev
    Hi there

    Will there be more than 1 tutorial in the PHP/Sessions category?

    I need to know this so that we can work out what the query string on the links should be. Once this is defined, we can work out the correct logic required in tutorials.php
    New thread activated as a continuation.....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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