SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 50
  1. #1
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <?php Select Newstext from news where (BEST SOLUTION?)

    hey,
    i'm "trying" to make my own content management as a newbie. You should understand that i'm getting some problems .
    What's the best way of showing("select") the latest news on a page. By using the curdate() ??? or anything esle ?

    i've tried this, in vain!
    could u correct the code and tell me the best command to get the latest news please?

    PHP Code:
    <?php
    mysql_select_db
    ("articles");
    $curdate curdate()
    $news mysql_query("select newstext from news where newsdate2 >= $curdate");

    if (
    $news) {
    echo(
    "Here are the latest news of $curdate");
    }
    else {
    echo(
    "No News were found!");
    }

    while ( 
    $row mysql_fetch_array($news) ) {
     echo(
    "<P>" $row["newstext"] . "</P>");

    }
    ?>

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

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI,

    You could try:

    select newstext from news ORDER BY ID DESC LIMIT 1

    That'd print out the latest news, and only one.

  3. #3
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you meant the latest news added in the database?, also, i think it'll change automatically when a new news will be added no?, please tell me a bit more about this function please?

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

  4. #4
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another problem,
    could somebody please tell me why this script doesn't add the news to the database?
    PHP Code:
    <?php
    mysql_select_db
    ("articles");

    if (
    $action == "add") {
    $add mysql_query("INSERT INTO news SET newstext='$text', newsdate='$date'");

    if(
    $add) {
    echo(
    "News has been added!");
    }
    else{
    echo (
    "There had been a problem inserting the news");
    }
    }
    Thanx again!
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    1. The first one gets the latest news from the database and displays it. Once you add more news, that is shown.

    2. You didn't connect to the database in the other one.

  6. #6
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no it isn't necessary to connect to the database on my localhost. I dunno why, it works without connecting!, i think because i didn't set any password. I prefer like this thought!, with the script i showed (2nd problem), i found out that it added the news but with empty news, and date, maybe i should put the whole script for you too test it, try it,

    PHP Code:
    <html>
    <head>
    <title>Areacool [add news]</title>
    </head>
    <body>
    <h3><p><b>Here Brian, you can add some news which wil appear as the latest news</b></h3></p>

    <p>Type your news:</p>

    <FORM ACTION=<?php echo($PHP_SELF); ?> METHOD=POST>
    Current Date <INPUT TYPE=TEXT NAME="date"><BR>
    <TEXTAREA NAME="news" ROWS=50 COLS=60 WRAP></TEXTAREA><BR>
    <INPUT TYPE=SUBMIT VALUE="GO">
    </FORM>

    <p><h4>Check your news</h4></p>
    <?php
    echo("Date written: <b>$date</b><p>News: $news</p>");
    ?>


    <p><b><h3><a href="add.php?action=add">ADD THOSE NEWS</a></b></h3></p>

    <?php
    mysql_select_db
    ("articles");

    if (
    $action == "add") {
    $add mysql_query("INSERT INTO news SET newstext='$text', newsdate='$date'");

    if(
    $add) {
    echo(
    "News has been added!");
    }
    else{
    echo (
    "There had been a problem inserting the news");
    }
    }

    ?>
    <p><a href="select.php">View the news!</a></p>
    Thanx!
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  7. #7
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh sorry, i forgot that you can't test it, as you don't have the database,......
    sorry again

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

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the news you forgot to actually get the information using select *....etc in that one.

    Also, are news and date actually set when you want to add the information to the database?

  9. #9
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can't declare CURDATE() as $curdate without first declarinf the variable. And it IS nessicary to connect to the database as far as I know. Unless you're running a really weird form of pconnect().

    Remember, you MUST either use PHP to declare what $curdate and $date, etc are, or you must use the built in MySQL functions. CURDATE() TIMESTAMP() UNIX_TIMESTAMP, etc.

    God Bless,

    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

  10. #10
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way to save the current date in a variable ?, maybe like this?

    $curdate= Curdate()
    or
    $curdate = mysql_query(curdate()) ,or something of that sort?

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

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol...what a train wreck.

  12. #12
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you read Kevin's PHP/MySQL tutorial? Not trying to discourage you, but you have not quite grasped the rules, regulations, and theory behind PHP, or any true scripting language for that matter.

    PHP, like any other scripting language uses vaiables, which can be called anything, but can hold anything. A variable can hold from one integer to the entire works of Shakespear. This allows a programmer to be able to have lot's of different types of data, and be able to work with them. In PHP variables are associated with a dollar sign ($), but in other languages there may not be any accoiated character. PHP (which is one reason why I love it) allows you to use a variable without calling it, which is very usefull. but unless you have given the variable a value, either by POST, URL (GET), or declared in your code somewhere:

    PHP Code:
    $var "data"
    I'm newer than you are to scripting, and younger in age, and after I read Kevin's article I have constructed a lot of programs that are currently in use by thousands of users daily.

    So I just would exort you to read through that article, get a book from Wrox press, and devour any post on this forum, as well as any tutorial or manual (http://www.mysql.com).

    God Bless,

    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

  13. #13
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM news WHERE TO_DAYS(FROM_UNIXTIME(unix_timestamp(),'%Y-%m-%d')) - TO_DAYS(FROM_UNIXTIME(post_date,'%Y-%m-%d')) = '1' ORDER BY ID DESC

    the $id can be any number of days back from the current day, 0 being today and anything higher to x number of days back.

    Try using that query, its fast and involves mysql to do all the work.

    Thats how I made a news script with newsposts categorized by day.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  14. #14
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exbabylon, i've read half of kevin's tutorial, and i've just finished creating a rather simple and small content management, where i can update my news, simply as that, but for my first "real" script, i've very happy! , don't worry, i know about variables, .............
    I'm just doing some errors that most of begginers do. But that's part of the of work. I'm really glad of having learned php. I can't imagine i can update my news!,
    Now, i should start learning how to present the data from the database to the html page, i mean presenting with arrays........

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

  15. #15
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, great! I would reccomend that you read through the entire tutorial, because it takes you through the entire process.

    Theiggsta, what exactly does that query do? I guess you lost me on that would you mind explaining?
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  16. #16
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    petersmc gave me a very cool select query that showed the last news inserted in the database, but now, i would like to know how to show the 10 or 20 latest news, understand ???, the 10 latest news on a page, by descending order, from newer to older?, thanx!

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

  17. #17
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured out what you did, I'd never seen the TO_DAYS or FROM_UNXTIME, before, so I was wondering. If you care to send a URL to where the definitions of those may be, or to explain the depths of them I would be gratefull, it is always good to expand the mind!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  18. #18
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    petersmc gave me a very cool select query that showed the last news inserted in the database, but now, i would like to know how to show the 10 or 20 latest news, understand ???, the 10 latest news on a page, by descending order, from newer to older?, thanx!

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

  19. #19
    ********* 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 petesmc
    HI,

    You could try:

    select newstext from news ORDER BY ID DESC LIMIT 1

    That'd print out the latest news, and only one.
    Is this the query you were refering to? In this case, then just change the LIMIT to the number of records you want. For example, for the last 10 records:

    SELECT newstext FROM news ORDER BY ID DESC LIMIT 10

  20. #20
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx, i'l try!,
    coming back after,
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  21. #21
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it worked, thanx again!

    Brian
    another question, can i put several forms that adds different data on ONE PAGE ? won't there be some problems ?
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  22. #22
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why does this doesn't show the text ( with 70 characters ?),
    when i view it on a browser, i see the name (author) , but not the text!

    PHP Code:
    <?php
    mysql_select_db
    ("articles");
    $view mysql_query(
     
    "select left(text, 70), date, name from ich ORDER BY ID DESC LIMIT 1");


    while (
    $row mysql_fetch_array($view)) {
     
    $datext $row["text"];
     
    $daname $row["name"];
     
    $dadate $row["date"];
     

    echo( 
    "<p><font face='Courier New, Courier, mono' size='2'><b><font color='#000066'>Author</font></b><font color='#999999'>:</font><font color='#000000'><b> 
      <font color='#3300FF'>
    $daname</font></b></font></font>
    </p>
    $datext
    "
    );
    What's the problem ?, in fact, can i use Left(text, 70), ......
    with mysql_query and with php ?
    Brian
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  23. #23
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    left(text, 70) as text

  24. #24
    Senior Webdesigner koolbrian's Avatar
    Join Date
    Dec 2000
    Location
    Mauritius
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i didn't really understand your reply. Use it as text HUH ?,
    remember that "text" is the name of a column in my database.

    Brian
    Any other replies would be VERY appreciated!
    BrianStudio - the webdesign company
    Professional & Affordable
    Brian Dove - Senior Graphic Designer
    Direct Hire: info@brianstudio.com

  25. #25
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In order to refer to a function's output in MySQL you must assign the output of the function an alias name to refer to in your disaply, so pete is saying assign the result of left(text, 50) to the alias name text so you can call it from your script like you did:

    $datext = $row["text"];
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •