SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast weekyd's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP and MySQL Questions...newbie needs help

    problem one:
    hi guys...learning php and mysql
    i have a database of 150 products. On the browser display next to each product there is a small picture for each product. The easy bit is..there's only 4 images. say 30 products have the same image, pic1.jpg, and 50 products have pic2.jpg and so on.
    i connect to my database using php

    let me give you a visual idea how it will display on browser


    <product_img> <product_id> <product_name> <product_price>
    <pic1.jpg> <001> <TV> <2.00>

    <pic3.jpg> <002> <fridge> <3.00>

    <pic1.jpg> <003> <antena> <2.00> and so on...

    <no pic> <004> <VCR> < price less>


    now i could manually store the image path relative to my root in the database field 150 times which will display the image but i am sure there's some easier way you guys have done it already in php...only four images that repeat and some of the products don't requre any image..

    can you guys help me? plz..


    problem 2:


    now this problem is kind of interesting..at least i thought it was

    suppose i have some site where data gets written to DB by the minute..
    I want to have a page that refreshes and gets the data from the database within a given time period...easy pizzy!..which i have done using javascript and php or even meta tags..

    but the only draw back is, the browser has to be refreshed each time when and/or if i want to retrieve the data from the database..i was wondering if there's in anyway mysql could communicate with the browser and notify and say "hey mr browser i have some new data, time to refresh or retrieve me" only when new data arrives....rather than mr browser continuously asking for the data?

    i hope i made it clear..and suggestions and URLs would be much appreciated...

    thanks guys

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    problem 1 -- define an images table, store the 4 image paths in there, assign each one a primary key value of a tinyint, place the appropriate key value into each product row instead of the image path, and do a JOIN when you want to pull information to display on the web page

    problem 2 -- not easily

    what you describe sounds like "push"

    see http://jamie.ideasasylum.com/2004/05...olled-pull.php
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast weekyd's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers r..the article looks interesting..

  4. #4
    SitePoint Enthusiast weekyd's Avatar
    Join Date
    Jun 2004
    Location
    UK
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    problem 1 -- define an images table, store the 4 image paths in there, assign each one a primary key value of a tinyint, place the appropriate key value into each product row instead of the image path, and do a JOIN when you want to pull information to display on the web page

    problem 2 -- not easily

    what you describe sounds like "push"

    see http://jamie.ideasasylum.com/2004/05...olled-pull.php

    hey r..

    would you pls kindly post the queriy for me plz..i dont know how to assign primary key value to each of the images..and if possible the JOINing query too..thanks

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    products
    img_id product_id product_name product_price
      23       001         TV         2.00
      26       002         fridge     3.00
      23       003         antena     2.00
    [null]     004         VCR        9.37
    
    images
    id image_url
    23 pic1.jpg
    24 pic2.jpg
    26 pic3.jpg
    27 pic4.jpg
    
    select P.product_id 
         , P.product_name 
         , P.product_price
         , coalesce(I.image_url,'no image') as product_image
      from products as P
    left outer
      join images as I
        on P.img_id = I.id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •