Activity Stream
48,167 MEMBERS
62659 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 6 of 6
  1.     
    #1

    Exclamation MySql Query

    Consider there is the following table.



    Now I want to query only the rows whose value is 1.

    I use the following code

    Code: 
    
    $sql="SELCET  name, reg, branch, year from i11 where sf='1'";
    $result=mysql_query($sql);
    while ($row=mysql_fetch_array($result))
    but I got the following warning

    Code: 
    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in \xampp\htdocs\reg\events.php on line 19


    Kindly give information about the correct query.

    Thank you.
    GoPantheoN Reviewed by GoPantheoN on . MySql Query Consider there is the following table. http://lulzimg.com/i14/384165.jpg Now I want to query only the rows whose value is 1. I use the following code Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    florijan.net
    You can check with the following if your mysql_query is being executed properly:


    Error: you have SELCET instead SELECT
    Code: 
    $sql="SELCET  name, reg, branch, year from i11 where sf='1'";
    Correct query:
    Code: 
    $sql = "SELECT  name, reg, branch, year FROM i11 WHERE sf='1'; ";

  4.     
    #3
    Thank you for the correction

  5.     
    #4
    Member
    Website's:
    LulzCovers.com LulzTroll.com
    Code: 
    $get=mysql_query("Select * from i11 where sf='1'");
    while($result = mysql_fetch_assoc($get))
    you can use field names instead of *
    Contact me for Traffic, SEO, WCDDL, Wordpress, IPB related Services or queries.
    Template Designing, PSD to HTML, Wordpress


  6.     
    #5
    Member
    Website's:
    florijan.net
    @deAthbLisS

    Using * in a query is great to get all the fields, but MySQL tends to have better queries when you specify which fields do you need to get from the MySQL table.

    If a MySQL table has 30 fields, and you need only 5 for your query, then selecting other 25 would be a huge overkill, as it would take more tie for MySQL to execute the query.
    Specifying table fields that you need to select is part of MySQL best practice programming and it's good to stick to it even if you have 3 fields in you table.

    Optimize where you can.

  7.     
    #6
    Ya right, I need only selected fields to be quried up on the given condition.

    Thank you death & ab1ko.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP - MySQL query to CSV export
    By ElitePirate in forum Web Development Area
    Replies: 2
    Last Post: 25th Jul 2012, 09:19 PM
  2. mysql query to export database
    By lenney in forum IP.Board
    Replies: 4
    Last Post: 7th May 2011, 03:43 PM
  3. mysql query help ($5 reward)
    By tdsii in forum Web Development Area
    Replies: 20
    Last Post: 10th Jan 2011, 11:52 PM
  4. WordPress database error MySQL server has gone away for query
    By blur88 in forum Webmaster Discussion
    Replies: 10
    Last Post: 27th May 2010, 08:43 PM
  5. Speed Up Your Web Site With MySQL Query Caching
    By BlaZe in forum Technical and Security Tutorials
    Replies: 1
    Last Post: 4th Nov 2009, 03:11 PM

Tags for this Thread

BE SOCIAL