SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 50 of 50
  1. #26
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but that's what i did, check my script in my previous post!, as u said!,
    another question: If a variable is created in the bottom of a script, will i be able to use it on the top of the script ?
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  2. #27
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am gonna try this one more time and then you are on your own.

    $view = mysql_query(
    "select left(text, 70), date, name from ich ORDER BY ID DESC LIMIT 1");

    needs to be

    $view = mysql_query(
    "select left(text, 70) as text, date, name from ich ORDER BY ID DESC LIMIT 1");


    See the difference?????

    You must assign the result of your function to an alias you DID NOT do that in your first try, you need to adjust it to look like the one I have above.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #28
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    If a variable is created in the bottom of a script, will i be able to use it on the top of the script ?
    That would take 30 seconds to test. Why don't you test that out and post the results.

  4. #29
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a big thanks to freddiedoesphp for helping me , but still another problem. I've created a very simple search page to search some text from a database. but the problem is that it only shows ONE result. If i searched "the" from the column text in the table ( where there are MANY "the" words in the table) , it would only show one record, not the all the records. Is there a way of doing it that way?,
    is it better to use the get or post form method ?, i think get because if the user bookmarks the page, the get would be saved ?,
    PHP Code:

    <?php
    mysql_select_db
    ("articles");

    if (isset(
    $search)) {

    $query mysql_query("Select left(text,80) as text, name, email, date, id from ich where text like '%$search%'");

    echo (
    "Here are the results for <b>$search</b>");

    while (
    $row mysql_fetch_array($query)) {
     
    $datext $row["text"];
     
    $daname $row["name"];
     
    $daemail $row["email"];
     
    $dadate $row["date"];
     
    $daid $row["id"];
    }
    echo(
    "<p><div id='Layer1' style='position:absolute; width:510px; height:20px; z-index:1; background-color: #000066; layer-background-color: #000066; border: 1px none #000000'> 
    <table width='98%' border='0'><tr><td width='18%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>ID<font color='#999999'>:</font></font><font face='Courier New, Courier, mono' size='2' color='#FFFFFF'>
    $daid</font></b></td>
          <td width='32%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>Date<font color='#999999'>:</font></font><font face='Courier New, Courier, mono' size='2' color='#FFFFFF'>
    $dadate</font></b></td>
          <td width='29%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>Author<font color='#999999'>:</font></font><font face='Courier New, Courier, mono' size='2'><a href='mailto:
    $daemail'><font color='#00CCFF'>$daname</a></font></b></td>
          <td width='50%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>Mail</font><font face='Courier New, Courier, mono' size='2' color='#FFFFFF'><font color='#CCCCCC'>:</font>
    $daemail</font></b></td>
        </tr>
      </table>
    </div></p>
    <p>.</p>
    <p>
    $datext</p>");
    }
    else {
    echo(
    "No keywords were given!");
    }

    ?>
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  5. #30
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another questions, why when i search through msn , or yahoo, i see the % sign?, any special reason ?, also, when i view the results from the search, i see the / sign nearly everywhere?, why ?
    example;
    Here are the results for look, it\'s good


    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  6. #31
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey,
    the / sign has dissapear in the
    Here are the results for look, it's good
    where / should be seen near the it'/s good!,
    where has that been?, any explanation?, does php transforms it or what ?
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  7. #32
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are ending the whlie { } loop too early - try this instead:
    PHP Code:
    <?php
    mysql_select_db
    ("articles");

    if (isset(
    $search)) {

    $query mysql_query("Select left(text,80) as text, name, email, date, id from ich where text like '%$search%'");

    echo (
    "Here are the results for <b>$search</b>");

    while (
    $row mysql_fetch_array($query)) {
        
    $datext $row["text"];
        
    $daname $row["name"];
        
    $daemail $row["email"];
        
    $dadate $row["date"];
        
    $daid $row["id"];
        
        echo(
    "<table width='98%' border='0'><tr><td width='18%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>ID<font color='#999999'>:</font></font><font face='Courier New, Courier, mono' size='2' color='#FFFFFF'>$daid</font></b></td>
              <td width='32%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>Date<font color='#999999'>:</font></font><font face='Courier New, Courier, mono' size='2' color='#FFFFFF'>
    $dadate</font></b></td>
              <td width='29%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>Author<font color='#999999'>:</font></font><font face='Courier New, Courier, mono' size='2'><a href='mailto:
    $daemail'><font color='#00CCFF'>$daname</a></font></b></td>
              <td width='50%'><b><font face='Courier New, Courier, mono' size='2' color='#FFCC00'>Mail</font><font face='Courier New, Courier, mono' size='2' color='#FFFFFF'><font color='#CCCCCC'>:</font>
    $daemail</font></b></td>
            </tr>
          </table>
        </div></p>
        <p>.</p>
        <p>
    $datext</p>");
    }

    ?>
    Also you can't do while (something) {do this} else {do that} as while does not support an ELSE clause. if you want to display an error message saying that there are no search results you should do this:
    PHP Code:
    if (mysql_num_rows($query) == 0)
    {
        echo 
    "No search results.";

    That checks the number of resutls returned from the mySQL query - if it is 0, then no results were returned so it displays an error message.

  8. #33
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been gone on a business trip for the past four days, and
    am appalled at the last three posts. Have you gone through
    Kevin's tutorial completely as of yet, like I suggested you do,
    as well as complete all of his work, and follow along with him
    while you coded it yourself? You are only going to get out of
    the tutorial as much as you put into it!

    Anyways, I will answer your questions:

    Question: Why did this query only bring back one result?
    Answer: Because you only allowed it to print once! You cut
    off the WHILE loop before you printed anything to the screen!
    What you effectively accomplished in that code is a very
    inefficient method of retrieving the last result from your
    searh! Move the closing of your WHILE loop directly above the
    closing of your if(isset).

    [b]Question: Why does the backslash sign dissapear?
    Answer: This one should be known to you, if you have read
    the turorial, however, I will reitterate what is in the article.
    PHP uses a control structure, and, therefore, certain
    charactars are used to manipulate data. MySQL does the
    same, and single quotes must ALWAYS be escaped before
    entering into the database. What's escaping? That is the
    process of placing a specified character, which happens to be
    the backslash in PHP, in front of that character. Example:

    Code:
    // Example One
    echo("<a href=\"test.php\"><font face=\"verdana,arial\" color=\"#000000\">
    <b>Shakespear, \"I'm but a crazy man, and though this may
    be madness, yet there is method in't\" - Hamlet Act III</b></font></a>");
    
    // Example Two
    echo('<a href="test.php"><font face="verdana,arial" color="#000000">
    <b>Shakespear, "I\'m but a crazy man, and though this may
    be madness, yet there is method in\'t" - Hamlet Act III</b></font></a>');
    
    // Example Three
    $test_var = "Shakespear, \"I'm but a crazy man, and though
    this may be madness, yet there is method in't" - Hamlet Act III";
    
    $test_var = addslashes($test_var);
    $sql = "INSERT INTO table SET test='$test_var'";
    Hopefully that will help you. If you've already read through
    Kevin's article, you may want to consider WebMonkey's, they
    also have a really well thought and laid out tutorial.

    God Bless, glad you're learning how to code!

    Alex Stanton
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  9. #34
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another small question THAT DOESN'T COVER KEVIN'S TUTORIAL!
    how to change the output for each row that's displayed. understand ? I u have seen my script, u should understand that it shows a table with the date, email, name, id and text. But i would like to change the color of the table after each output ( table with id, email, name, date and text) ???, hope u understood, or please tell me a tutorial that covers this kind of problems, displaying mysql data,


    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  10. #35
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another small question that's a bit out of context. With php/mysql, data is stored in Mysql, but with perl, where is the data kept?, it should be kept somewhere because it's a server side language . Do you advise me to learn perl ??, or continue to learn php, DEEPLY ???, i like php/mysql, really cool!

    Brian
    Ps: Is perl some ways similar to php/mysql , variables, then ?
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  11. #36
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To change the color of every other row:

    PHP Code:

    $i 
    1;
    while(
    $row mysql_fetch_array($result)){
        
    // Remainder of $i divided by two, determine if $i is even or odd
        
    if($i == 0){
            
    $color "red";
        }else{
            
    $color "blue";
        }
        
    extract($row);
        echo(
    "<tr bgcolor=\"$color\"><td>$title</td><td>"substr($content0150) . "</td><td>$date</td></tr>");
        
    $i++;

    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  12. #37
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Koolbrain,

    I would definetally reccomend that you stick with PHP untill you fell completely confident with it. And, yes, PERL is similiar to PHP in the fact that a lot of it's control structure is based upon the C format. However, it is not imbedded in HTML, as is PHP, making it usefull for more than just the internet.

    PERL retrieves it's data just like PHP does-- from whatever you want to retrieve it from, database, or the most common in PERL- flat file. The only hinderance I find in PERL is it does not have the broad range of functions that PHP has. And, as with PHP, PERL is excellent with ASCII manipulation. And, while you can connect to a database server with PERL, it not as easy as with PHP, and since PHP has built in like 10 different databases, it makes things really simple.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  13. #38
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exbabylon, koolbrian and others your code for alternating row colors works fine but can be accomplished in half the code by using

    PHP Code:
    $i 1;
    while(
    $row mysql_fetch_array($result)){
        
    // Remainder of $i divided by two, determine if $i is even or odd
        
    extract($row);
        
    printf('<tr bgcolor="%s"><td>%s</td><td>%s</td><td>%s</td></tr>', ($i ==0) ? "red" "blue"$titlesubstr($content0150), $date);
        
    $i++;
        } 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #39
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, I have never used printf() before in my coding, or switches.... I like your method, great example!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  15. #40
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just be ready for the barrage(s/p?) of comments about how printf() is soooo.... much slower than echo or print. Take them as they come, I am used to it by now and to tell you the truth I haven't seen much of a drastic difference between them. Although I have never written an app geared for enough traffic that one might see that kind of difference, and by that much traffic I mean millions of hits a day.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #41
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course it's a little bit slower... I mean, it goes through an entire control structure... and readability may not be, uh, premium when working on a group project. But great in a lot of different smaller apps and simple dirty programs.

    It's hard to get a million hits a day... I only get 250 -300 thousand a day, hardly even half of that.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  17. #42
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which site is it that you get 250 -300 thousand hits per day, and if thats the case why are you not retired on a beach from advertising revenue?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  18. #43
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, I asked that not because I don't believe you, but because I saw your age was 14 in your profile and that is pretty impressive for a 14 yr old. Thats all.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  19. #44
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy,

    Are we talking page hits or real page views? I'm talking hits, pure hits, every image, every javascript, every everything. Sorry to bring in confusion if I am. My site is really my father's business, and includes www.LoadSwap.com and www.BeartoothBullets.com, both of which are on the same shared hosting account. Most of the hits come from the forum and loadswap.

    Sorry for the confusion if I caused any, I'm still going to school and working on small business sites.

    Alex
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  20. #45
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah.. sorry for the confusion, I meant page views and still 250,000 - 300,000 hits is pretty impressive.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  21. #46
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wish! Imagine... even 100,000 page views! My current page views is, accoriding to http-anylise, 20-25 thousand, but this summer has dropped them down to 15-20, even got 11 a few days ago .
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  22. #47
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by koolbrian
    another small question that's a bit out of context. With php/mysql, data is stored in Mysql...
    Data is not kept in MySQL with PHP unless you setup a database and create a PHP script to store and retrieve data from the MySQL database. PHP is most known for interacting with MySQL because MySQL is free and PHP has built-in functions for it, but it also does for other RMDBS (I think) and can be coded to do so regardless of whether it has built-in functions to do so.
    Kevin

  23. #48
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    Just be ready for the barrage(s/p?) of comments about how printf() is soooo....
    much slower than echo or print. Take them as they come, I am used to it by now and to
    tell you the truth I haven't seen much of a drastic difference between them. Although I
    have never written an app geared for enough traffic that one might see that kind of
    difference, and by that much traffic I mean millions of hits a day.


    Yeah, you will be wasting a couple of clock cycles and maybe an extra registry or two

    As exbabylon points out some ppl will have a dislike for using printf because it adds
    extra complexity, requires additional knowledge that a newbie may not have, and
    looks ugly I know it is elegent to your eyes - so each to their own. I do remember
    when I was starting learning C++ a couple of years ago at school that if I came
    accross code that had a C-style call to printf in it my eyes would just glaze over. It
    was overload for my soft brain when I was trying to learn the basics and grapple with
    simple syntax.

    BTW, just for a giggle, you can still cut another statement from that code like so...

    PHP Code:
    $i*=*1;
    while(
    $row*=*mysql_fetch_array($result)){
    ****//*Remainder*of*$i*divided*by*two,*determine*if*$i*is*even*or*odd
    ****extract($row);
    ****printf('<tr*bgcolor="%s"><td>%s</td><td>%s</td><td>%s</td></tr>',
     
    ****($i++*%*2*==0)*?*"red"*:*"blue",*$title,*substr($content,*0,*150),*$date);
    ****

  24. #49
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanc for all the replies since now.
    Before, someone gave me a command that show the latest data stored in the db, the last data.now i would like to know how to show 1 data that was inserted before the last data ?, understand ?, the before last data , how to show it?

    Hope there's another reply on that subject,
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  25. #50
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I'm not sure how you are keeping track of what order things are being added to the database table. The best way is with a date or timestamp column. So I will order by a field called "dateEntered" in my query, but it is whatever is the field that will keep order of when things have been added. Anyway, the important thing is that you do this with the LIMIT clause.

    This will give you the *last* record in the database:

    SELECT *
    FROM tableName
    ORDER BY dateEntered DESC
    LIMIT 1

    This is actually a shorthand way of saying

    SELECT *
    FROM tableName
    ORDER BY dateEntered DESC
    LIMIT 0,1

    Which is saying skip the first 0 records in the result set and return the next 1 records.

    So to find out the record inserted *before* the last one you would use this

    SELECT *
    FROM tableName
    ORDER BY dateEntered DESC
    LIMIT 1,1

    Which is saying skip the first (1) record and return the next 1 record. To find the record before the record before the last (ie, the third last record) would be,

    SELECT *
    FROM tableName
    ORDER BY dateEntered DESC
    LIMIT 2,1

    and so on


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
  •