SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 39 of 39
  1. #26
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well as for my op, I am learning!!

    Code:
    mysql_select_db($dbname, $conn) or exit(mysql_error());
    
    $loopResult = ''; // leave blank to start var for loop
    $result = mysql_query('SELECT `cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while($row = mysql_fetch_assoc($result)) {
    	$loopResult = ' 
            <div class="dlitem">
             <div class="dltitle"><a href="'.$row['dl_page'].'">'.$row['dl_name'].'</a></div>
             <div class="dlimage"><a href="'.$row['dl_page'].'"><img src="'.$row['dl_image'].'" /></a></div>
             <div class="dldesc">'.$row['dl_desc'].'</div>
             <div class="dllink"><a href="'.$row['dl_link'].'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
        ';
    }
    echo $loopResult;
    ?>
    Thanks everyone!!

  2. #27
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay Im stuck again, this is really confusing!!

    Why is it when i use the ugly method, being:

    Code:
    $result = mysql_query('SELECT `dl_id`,`cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while($row = mysql_fetch_assoc($result)) {
    	$dl_id = $row['dl_id'];
    	$dl_page = $row['dl_page'];
    	$dl_name = $row['dl_name'];
    	$dl_image = $row['dl_image'];
    	$dl_desc = $row['dl_desc'];
    	$dl_row = $row['dl_row'];
    	echo" 
            <div id='.$dl_id.' class=\"dlitem\">
             <div id='.$dl_name.' class=\"dltitle\"><a href=\"'.$dl_page.'\">'.$dl_name.'</a></div>
             <div id='.$dl_image.' class=\"dlimage\"><a href=\"'.$dl_page.'\"><img src=\"'.$dl_image.'\" /></a></div>
             <div id='.$dl_desc.' class=\"dldesc\">'.$dl_desc.'</div>
             <div id='.$dl_link.' class=\"dllink\"><a href=\"'.$dl_link.'\" type=\"text/vnd.sun.j2me.app-descriptor\">DOWNLOAD NOW</a></div>
            </div>
        ";
    }
    It displays the 2 items in my database that match the query.

    But when i do this:
    Code:
    $loopResult = ''; // leave blank to start var for loop
    $result = mysql_query('SELECT `dl_id`,`cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while($row = mysql_fetch_assoc($result)) {
    	$dl_id = $row['dl_id'];
    	$dl_page = $row['dl_page'];
    	$dl_name = $row['dl_name'];
    	$dl_image = $row['dl_image'];
    	$dl_desc = $row['dl_desc'];
    	$dl_row = $row['dl_row'];
    	$loopResult = ' 
            <div id='.$dl_id.' class="dlitem">
             <div id='.$dl_name.' class="dltitle"><a href="'.$dl_page.'">'.$dl_name.'</a></div>
             <div id='.$dl_image.' class="dlimage"><a href="'.$dl_page.'"><img src="'.$dl_image.'" /></a></div>
             <div id='.$dl_desc.' class="dldesc">'.$dl_desc.'</div>
             <div id='.$dl_link.' class="dllink"><a href="'.$dl_link.'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
        ';
    }
    echo $loopResult;
    It only displays only one of the two possible matches in the query?

    EDIT: I know the ugly bit of code is atrocious, but it does display both items, what is the difference here?

  3. #28
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,146
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    In the last implementation loopResult will always be equal to the value assigned in the last iteration. The = means change the value each time, essentially assigning a new value each iteration overriding the existing one. I think what your after is concatenation (notice the dot).

    PHP Code:
    $loopResult ''// leave blank to start var for loop
    $result mysql_query('SELECT `dl_id`,`cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while(
    $row mysql_fetch_assoc($result)) {
        
    $dl_id $row['dl_id'];
        
    $dl_page $row['dl_page'];
        
    $dl_name $row['dl_name'];
        
    $dl_image $row['dl_image'];
        
    $dl_desc $row['dl_desc'];
        
    $dl_row $row['dl_row'];
        
    $loopResult.= 
            <div id='
    .$dl_id.' class="dlitem">
             <div id='
    .$dl_name.' class="dltitle"><a href="'.$dl_page.'">'.$dl_name.'</a></div>
             <div id='
    .$dl_image.' class="dlimage"><a href="'.$dl_page.'"><img src="'.$dl_image.'" /></a></div>
             <div id='
    .$dl_desc.' class="dldesc">'.$dl_desc.'</div>
             <div id='
    .$dl_link.' class="dllink"><a href="'.$dl_link.'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
        '
    ;
    }
    echo 
    $loopResult
    The only code I hate more than my own is everyone else's.

  4. #29
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    In the last implementation loopResult will always be equal to the value assigned in the last iteration. The = means change the value each time, essentially assigning a new value each iteration overriding the existing one. I think what your after is concatenation (notice the dot).

    PHP Code:
    $loopResult ''// leave blank to start var for loop
    $result mysql_query('SELECT `dl_id`,`cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while(
    $row mysql_fetch_assoc($result)) {
        
    $dl_id $row['dl_id'];
        
    $dl_page $row['dl_page'];
        
    $dl_name $row['dl_name'];
        
    $dl_image $row['dl_image'];
        
    $dl_desc $row['dl_desc'];
        
    $dl_row $row['dl_row'];
        
    $loopResult.= 
            <div id='
    .$dl_id.' class="dlitem">
             <div id='
    .$dl_name.' class="dltitle"><a href="'.$dl_page.'">'.$dl_name.'</a></div>
             <div id='
    .$dl_image.' class="dlimage"><a href="'.$dl_page.'"><img src="'.$dl_image.'" /></a></div>
             <div id='
    .$dl_desc.' class="dldesc">'.$dl_desc.'</div>
             <div id='
    .$dl_link.' class="dllink"><a href="'.$dl_link.'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
        '
    ;
    }
    echo 
    $loopResult

    Okay thanks man, would that then mean that no unique id is needed for each div created?

    EDIT: I see the uniue id is not needed with this method, thanks alot!! that is so cool!

  5. #30
    SitePoint Zealot LinuxFreelancer's Avatar
    Join Date
    Jun 2011
    Location
    Boston, Ma, Usa
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, no unique id is needed. However, if you want one do this:
    PHP Code:
    $loopResult '';
    $i=0// <<< create the $i variable assigned as zero
    $result mysql_query('SELECT `dl_id`,`cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while(
    $row mysql_fetch_assoc($result)) {
        
    $i++; //Take $i and add 1 to it on each pass in the loop
        
    $dl_id $row['dl_id'];
        
    $dl_page $row['dl_page'];
        
    $dl_name $row['dl_name'];
        
    $dl_image $row['dl_image'];
        
    $dl_desc $row['dl_desc'];
        
    $dl_row $row['dl_row'];
        
    // Below, $i becomes your unique div id
        
    $loopResult.= 
            <div id="divId'
    .$i.'" class="dlitem">
             <div id='
    .$dl_name.' class="dltitle"><a href="'.$dl_page.'">'.$dl_name.'</a></div>
             <div id='
    .$dl_image.' class="dlimage"><a href="'.$dl_page.'"><img src="'.$dl_image.'" /></a></div>
             <div id='
    .$dl_desc.' class="dldesc">'.$dl_desc.'</div>
             <div id='
    .$dl_link.' class="dllink"><a href="'.$dl_link.'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
        '
    ;
    }
    echo 
    $loopResult

  6. #31
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LinuxFreelancer View Post
    No, no unique id is needed. However, if you want one do this:
    PHP Code:
    $loopResult '';
    $i=0// <<< create the $i variable assigned as zero
    $result mysql_query('SELECT `dl_id`,`cat_id`,`model_id`,`dl_name`,`dl_image`,`dl_image_alt`,`dl_desc`,`dl_link`,`dl_page` FROM `download` WHERE `cat_id` = "2" && (`model_id` = "1" || `model_id` = "'.$chosen.'")');
    while(
    $row mysql_fetch_assoc($result)) {
        
    $i++; //Take $i and add 1 to it on each pass in the loop
        
    $dl_id $row['dl_id'];
        
    $dl_page $row['dl_page'];
        
    $dl_name $row['dl_name'];
        
    $dl_image $row['dl_image'];
        
    $dl_desc $row['dl_desc'];
        
    $dl_row $row['dl_row'];
        
    // Below, $i becomes your unique div id
        
    $loopResult.= 
            <div id="divId'
    .$i.'" class="dlitem">
             <div id='
    .$dl_name.' class="dltitle"><a href="'.$dl_page.'">'.$dl_name.'</a></div>
             <div id='
    .$dl_image.' class="dlimage"><a href="'.$dl_page.'"><img src="'.$dl_image.'" /></a></div>
             <div id='
    .$dl_desc.' class="dldesc">'.$dl_desc.'</div>
             <div id='
    .$dl_link.' class="dllink"><a href="'.$dl_link.'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
        '
    ;
    }
    echo 
    $loopResult
    Wow that is very cool, and im starting to see that the possibilities are truly endless!

    But speaking of unique id's, i suppose those would be useful if I wanted to track data such as the most popular downloads? But im guessing if this were the case, then the id would need to be a bit more complex because with your way "xapp" could be displayed with a div id of 1, 100 or 101 depending on the scripts output which would vary depending on the users input, or in my case $chosen?

    Well this is something to certainly put some thought into, but theres no house without a foundation and speaking of that, thank you for that pic of your db freelancer, I rebuild mine as a result and spend some time looking at db normalization. I think mine would be classed as the first normal form now? In anycase, i think it's a much better start, im going to amend your script on my test page so that it reflects the new db that, along with the few changes i made to the query and its variables.

    This is exciting!

  7. #32
    SitePoint Zealot LinuxFreelancer's Avatar
    Join Date
    Jun 2011
    Location
    Boston, Ma, Usa
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To track downloads just have a second script redirect to the download prior to recording the traffic in your database.

    Example:
    http://localhost/tracking.php?id=1

    the id in the url should be dl_id from your database.

    so when clicked the tracking script checks to see if the dl_id exists and what the user should be redirected to. Prior to redirect it records the download like something like this:


    PHP Code:
    mysql_query('UPDATE `download` SET `count`=(count+1) WHERE `dl_id`="' $id '"') or die(mysql_error()); 
    I think mine would be classed as the first normal form now?
    I didn't quite understand what you meant here

  8. #33
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay interesting, figured out that the problem i was haing with your script not loading was due to me inserting
    Code:
    $max_results = 30;
    into the wrong place, i have now added it just above this line
    Code:
    $from = (($page * $max_results) - $max_results);"
    The page now loads, but with this error:

    "Fatal error: Allowed memory size of 18874368 bytes exhausted (tried to allocate 18612364 bytes) in /blah/server/root/test3.php on line 191"

    Line 191 is
    Code:
     ';
    it appears just after this:

    Code:
    $loopResult.= ' 
            <div id="divId'.$i.'" class="dlitem">
             <div id='.$dl_name.' class="dltitle"><a href="'.$dl_page.'">'.$dl_name.'</a></div>
             <div id='.$dl_image.' class="dlimage"><a href="'.$dl_page.'"><img src="'.$dl_image.'" /></a></div>
             <div id='.$dl_desc.' class="dldesc">'.$dl_desc.'</div>
             <div id='.$dl_link.' class="dllink"><a href="'.$dl_link.'" type="text/vnd.sun.j2me.app-descriptor">DOWNLOAD NOW</a></div>
            </div>
    What causes issues like this?

  9. #34
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well now, that seems like a logical approach, a million times better too! Quite interesting indeed.

    But as for what i meant, umm... Well i dont exactly know myself, but i found references to that term on these pages:

    MySQL :: An Introduction to Database Normalization

    and

    Creating A Quick MySQL Relational Database Tutorial Using All Common Relationships - Web and dedicated hosting tutorials by Anchor

    was quite an interesting read.

  10. #35
    SitePoint Zealot LinuxFreelancer's Avatar
    Join Date
    Jun 2011
    Location
    Boston, Ma, Usa
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    send me the modified script. I see a double quote at:

    $from = (($page * $max_results) - $max_results);"

    Not sure if that is on accident when posting, but once I see your modified code I will show you the fix.

    The links you posted are to to an infinite loop, not the links your posted.

  11. #36
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LinuxFreelancer is a god amoung men I cannot thank you enough for the incredible amount of insight you have brought me!!! Thank you for ALL of your help!

    As for everyone else, i am truly so greatful for all the input you guys have given me. I went from knowning nothing about a bare minimum of php to oficially having my first working REAL script, which is going to help me like noone could believe

    The visits to my site have gone up 762.71% this month... Now common 989283829297486% HAHA!

  12. #37
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @blackberryfan - do you really need to set up your HTML will all those divs?

    Code HTML4Strict:
    <!-- your current setup -->
    <div>
    	<div><a href="">DL Name</a></div>
    	<div><a href=""><img src="" /></div>
    	<div>Description</div>
    	<div><a href="">Download Now!</a></div>	
    </div>    
     
    <!-- somewhat better semantic markup -->
    <div>
    	<h4><a href="">DL Name</a></h4>
    	<a href=""><img src="" /></a>
    	<p>Description</p>
    	<p><a href="">Download Now!</a></p>
    </div>

    just a thought.....

  13. #38
    SitePoint Zealot blackberryfan's Avatar
    Join Date
    Nov 2010
    Location
    middleOnowhere, South Africa.
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And thank you for the thought...

    It's one that i'm going to have to put alot of thought into before I'll be able to reply.

    But point taken, thanks!!

    Edit:

    $shortAnswer = $no;

  14. #39
    SitePoint Zealot LinuxFreelancer's Avatar
    Join Date
    Jun 2011
    Location
    Boston, Ma, Usa
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is nothing from with the divs as long as they are needed to style each line differently.


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
  •