Jump to content

heldenbrau

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by heldenbrau

  1. I meant I don't want it to run unless num_rows >0
  2. I have posted the exact code that I'm running. I know that it's important to post the exact code, it has been doing my head in all night. I just want to get on and get it finished, but this "if" thing has baffled me. I'm still working out how to do the thing I'm trying to do, but need to understand why the if doesn't work.
  3. It shows this <a class="topseltxt2" href="gem.php?cat=">Round Brilliant pos44</a><br/> <div class="contain" id="dczcat1RoundBrilliant"> <div class="menuitems" id="dczcat1RoundBrilliant2">dczcat1RoundBrilliantWhiteWhiteSELECT * FROM dczcat1RoundBrilliantWhite ORDER BY positionshould not be displayed if it doesn't say Pumpkin aboveLEVEL69:3 <div class="menutitles" onmouseover="document.getElementById('dczcat1RoundBrilliantWhite').style.display='block';document.getElementById('dczcat1RoundBrilliantWhite2').style.display='block';" onmouseout="document.getElementById('dczcat1RoundBrilliantWhite').style.display='none';document.getElementById('dczcat1RoundBrilliantWhite2').style.display='block';" >
  4. $sql = "SELECT * FROM dczcat1 ORDER BY position"; if ($result = $mysqli->query($sql)){ if ($result->num_rows > 0){ while ($row = $result->fetch_array()){ $table=$row[cattable]; echo"$table"; $scat2=$table . 2; echo"$csat"; $cat=$row[cat]; echo"$cat"; $sql="SELECT * FROM $table ORDER BY position"; echo"$sql"; if($result=$mysqli->query($sql)){ if($result->num_rows>0){ echo"Pumpkin"; while ($row = $result->fetch_array()){ echo"<br />should not be displayed if it doesn't say Pumpkin above"; $level+=1; echo"LEVEL69:$level"; echo<<<HTML <div class = "menutitles" onmouseover="document.getElementById('$table').style.display='block';document.getElementById('$scat2').style.display='block';" onmouseout="document.getElementById('$table').style.display='none';document.getElementById('$scat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$fullcat">$cat pos44</a><br/> <div class="contain" id="$table"> <div class="menuitems" id="$scat2"> HTML; $table=$row[cattable]; echo "$table"; $scat2= $table . 2; echo "$scat"; $cat = $row[cat]; echo "$cat"; select($cat, $table, $scat2, $mysqli, $level); } }else if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$table'>$cat pos2</a><br/> "; echo"table:$table"; }else{ While($row=$result->fetch_array()){ $table=$row[cattable]; $scat2= $table . 2; $cat = $row[cat]; echo" <a class='topseltxt2' href='gem.php?cat=$table'>$cat pos3</a><br/> ";} $level-=1; } }else{ die("ERROR: Could not execute query $sql." . $mysqli->error); }echo"</div> </div> </div>"; } } }else{ die("ERROR: Query failed: $sql." . $mysqli->error); } At line 15 it says echo "Pumpkin" and below after the while loop it says "should not be displayed unless it says pumpkin above" When I run the above code it displays: should not be displayed unless it says pumpkin above No Pumpkin, how is this possible, if num_rows is greater than 0, then it should either display the word pumpkin, or it should skip everything between the {}'s shouldn't it? I don't want the while loop to run if num_rows is greater than 0, but it does and I'm sure it shouldn't be.
  5. Btw though, is there any way to generate variable names like what I originally wanted to do?
  6. Thanks pineapple, that $mysqli was the problem, it's sort of working now, cheers.
  7. The error is not line 60 any more, that was caused by a mistake now fixed. The error is now line 11 which is in the function. I have updated the code now. function select($fullcat) { echo"fullcat: $fullcat"; $sql="SELECT cat FROM $fullcat ORDER BY position"; if($result=$mysqli->query($sql)){ $count=+1; if($result->num_rows>0){ $level =+1; echo<<<HTML <div class="menutitles" onmouseover="document.getElementById('$fullcat').style.display='block';document.getElementById('$fullcat2').style.display='block';" onmouseout="document.getElementById('$fullcat').style.display='none';document.getElementById('$fullcat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$fullcat"></a><br/> <div class="contain" id="$fullcat"> <div class="menuitems" id="$fullcat2"> HTML; select($fullcat); }else{$level=-1; if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$fullcat'></a><br/> "; }else{ While($row=$result . $count->fetch_array()){ $scat=replace($row[cat]); $fullcat="$fullcat" . $scat; echo" <a class='topseltxt2' href='gem.php?cat=$fullcat'></a><br/> ";} } } } return($fullcat); } $sql = "SELECT cat FROM dczcat1 ORDER BY position"; if ($result = $mysqli->query($sql)){ if ($result->num_rows > 0){ $count=+1; while ($row = $result->fetch_array()){ $scat=replace($row[cat]); $scat2=replace($row[cat]) . 2; $cat=$row[cat]; $fullcat="dczcat1" . $scat; $fullcat2="dczcat1" . $scat . 2; $sql="SELECT cat FROM $fullcat ORDER BY position"; if($result=$mysqli->query($sql)){ $count=+1; if($result->num_rows>0){ $level =+1; echo<<<HTML <div class="menutitles" onmouseover="document.getElementById('$fullcat').style.display='block';document.getElementById('$fullcat2').style.display='block';" onmouseout="document.getElementById('$fullcat').style.display='none';document.getElementById('$fullcat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$fullcat"></a><br/> <div class="contain" id="$fullcat"> <div class="menuitems" id="$fullcat2"> HTML; select($fullcat); }else{$level=-1; if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$fullcat'></a><br/> "; }else{ While($row=$result . $count->fetch_array()){ $scat=replace($row[cat]); $fullcat="$fullcat" . $scat; echo" <a class='topseltxt2' href='gem.php?cat=$fullcat'></a><br/> ";} } } }echo"</div> </div> </div>"; } } }
  8. This is line 60 while ($row = $result->fetch_array()){ It is meant to be for a left side bar, the categories are in different tables. It is meant to list the first category from the first table, then check to see if there are any categories listed in the second table. If no categories in the second table, then it moves on and writes just 1 category in the side bar. If there are categories in the second table, then it lists them in a pop up menu and so on until all the levels of the pop up menu are showing.
  9. I have a recursive sql query. I'm doing this with an sql query as a function. Here is the function: function select() { $sql="SELECT cat FROM $scat"; if($result=$mysqli->query($sql)){ if($result->num_rows>0){ $level =+1; echo<<<HTML <div class="menutitles"> onmouseover="document.getElementById('$scat').style.display='block';document.getElementById('$scat2').style.display='block';" onmouseout="document.getElementById('$scat').style.display='none';document.getElementById('$scat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$scat"></a><br/> <div class="contain" id="$scat"> <div class="menuitems" id="$scat2"> HTML; select(); }else{$level=-1; if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$scat'></a><br/> "; }else{ While($row=$result->fetch_array()){ $scat=replace($row[cat]); echo" <a class='topseltxt2' href='gem.php?cat=$scat'></a><br/> ";} } } } } and this is the database query with the function added to it: $level=1; $count=0; $sql = "SELECT cat FROM dczcat1 ORDER BY position"; if ($result = $mysqli->query($sql)){ if ($result->num_rows > 0){ $count=+1; while ($row = $result->fetch_array()){ $scat=replace($row[cat]); $scat2=replace($row[cat]) . 2; $cat=$row[cat]; $sql="SELECT cat FROM $scat"; if($result=$mysqli->query($sql)){ $count=+1; if($result->num_rows>0){ $level =+1; echo<<<HTML <div class="menutitles"> onmouseover="document.getElementById('$scat').style.display='block';document.getElementById('$scat2').style.display='block';" onmouseout="document.getElementById('$scat').style.display='none';document.getElementById('$scat2').style.display='block';" > <a class="topseltxt2" href="gem.php?cat=$scat"></a><br/> <div class="contain" id="$scat"> <div class="menuitems" id="$scat2"> HTML; select(); }else{$level=-1; if($level==1){echo" <a class='topseltxt' href='gem.php?cat=$scat'></a><br/> "; }else{ While($row=$result . $count->fetch_array()){ $scat=replace($row[cat]); echo" <a class='topseltxt2' href='gem.php?cat=$scat'></a><br/> ";} } } }echo"</div> </div> </div>"; } } } I get the error: Fatal error: Call to a member function fetch_array() on a non-object in /home/kangerc1/public_html/zleftsidebar.php on line 60 I think this is because I am using $result more than once and I need to call it $result1 $result2 $result3 etc. but how can I generate the name of the variable?
  10. I am always having problems with the clear property. It seems simple to understand, but it never works as simply. Here is the page I'm having a problem with http://www.kangercourt.com/temp.php Here is the .one{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; clear:both; } .two{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; display:none; clear:both; } .three{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; display:none; clear:both; } .level{ border: solid 0px; height:30px; width:70px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; clear:none; } .levelhid{ border: solid 0px; height:30px; width:70px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; display:none; clear:both; } .level2{ margin-left: 50px; border: solid 0px; height:30px; width:150px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; clear:none; } .level2hid{ margin-left: 50px; border: solid 0px; height:30px; width:90px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; display:none; clear:both; } .level3{ margin-left: 100px; border: solid 0px; height:30px; width:150px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; clear:both; } .level3hid{ margin-left: 100px; border: solid 0px; height:30px; width:150px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; display:none; clear:both; } .box{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; clear:right; } .boxy{ border: solid 1px; padding:4px; height:auto; width:auto; float:right; text-align:left; vertical-align:middle; margin:2px; clear:none; } .boxhid{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; display:none; clear:right; } .box2{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; clear:right; } .box2hid{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; display:none; clear:right; } br{ clear:both; } #expand2{ border: solid 1px; } #expand3{ border: solid 1px; } .plus{ width:22px; height:20px; background: url('/images/plus.png'); } .delbut{ border-color:red; } .delform{ float:left; clear:left; vertical-align:bottom; } css I am viewing this in Firefox and here is what I need to understand: 1. The property for the form delform which contains the del button at the top left says clear:left; I understand this to mean that no floating objects can appear on the left of it but it is ok for floating objects to appear on the right. So why does the next object which is a div called 'level' which has a value of clear: 'none'; go to the next line? 2. When I click the far right + sign to make the next level of cats appear, they use the same classes, but this time the del button doesn't clear objects to the right of it and the level div does, why is that? 3. And in Internet explorer. The first category, the del button is cleared to the right, but is ok in the next category, until you get to the last box div in that second cat div, it then fails to clear the the right, why? There is something I'm really not getting about clearing.
  11. Thanks for the explanation, I'll remember that next time I need compare values of styles.
  12. I will put a link to the page, then you can see what it does too. A bit of a mess at the moment, but when I clean it up, it should look like an expandable category menu. http://www.kangercourt.com/temp.php Internet explorer is version 8
  13. .box2{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; clear:right; } .box2hid{ border: solid 1px; padding:4px; height:auto; width:auto; float:left; text-align:left; vertical-align:middle; margin:2px; display:none; clear:right; In Firefox, the next element which is: .levelhid{ border: solid 0px; height:30px; width:150px; float:left; text-align:right; padding-right:5px; vertical-align:bottom; display:none; clear:both; } Appears on the next line, but in IE, the box2 divs don't clear to the right, they all lign up in a line with one next to the other, why is this?
  14. Yes, now it works in both browsers, although I don't understand why. Very new to javascript. Thanks again for your help.
  15. Spoke too soon. In IE the plus changes to a minus, but doesn't change back into a plus again when I click it a second time. Here is the script: <style type='text/css'>@import url(styles/addcat.css);</style> <script type="text/javascript"> function toggleBg(plus) { if (document.getElementById(plus).style.backgroundImage=='url("/images/minus.png")'){ document.getElementById(plus).style.backgroundImage="url('/images/plus.png')"; }else{ document.getElementById(plus).style.backgroundImage="url('/images/minus.png')"; } } </script>
  16. ok, thanks for the tip, I've changed it to use backgroundImage and match the url only and it works in Firefox and Ie, just seen that the rest of the page is all over the place in IE though so more work to be done. Thanks for getting this to work.
  17. I have solved it now, the bit where it says: if (document.getElementById(plus).style.background=="url('/images/plus.png')"{ document.getElementById(plus).style.background="url('/images/minus.png')"; } Should be if (document.getElementById(plus).style.background=='url("/images/minus.png") repeat scroll 0% 0% transparent'){ document.getElementById(plus).style.background="url('/images/plus.png')"; I was able to see this by printing out the properties of the button with the alert.
  18. Yes, that is what is causing it to not work, the syntax error. Thanks for your help, that is the first part of the problem solved.
  19. <script type="text/javascript"> function toggleBg(plus) { alert("This is a test alert message"); if (document.getElementById(plus).style.background=="url('/images/plus.png')"{ document.getElementById(plus).style.background="url('/images/minus.png')"; }else{ document.getElementById(plus).style.background="url('/images/plus.png')"; } } </script>
  20. How would I do that so that I could print out the property of document.getElementById(plus).style.background in the alert message. The function togglebg is called when somebody clicks a button, I want the alert to tell me what the background style is. If I put the alert box code inside the fuction togglebg, nothing happens, but togglebg is triggered by an event.
  21. <script type="text/javascript"> function toggleBg(plus) { if (document.getElementById(plus).style.background=="url('/images/plus.png')"{ document.getElementById(plus).style.background="url('/images/minus.png')"; }else{ document.getElementById(plus).style.background="url('/images/plus.png')"; } } alert("This is a test alert message"); </script> I wanted to change the image of a button when it is clicked from a plus to a minus and then back to a minus. The problem is, it won't change when clicked and if I put minus in the the else bit, it changes to a minus. "url('/images/plus.png')" doesn't seem to match the actual property, so I wanted to get a printout of the actual property using an alert box. But the alert box won't even work when it is in the presence of that function. If I delete the function from the script area, the alert box works. Why doesn't the alert box work in the script above?
  22. Sorry just seen I have forgot to add (plus) and the curly brackets {} I have now copied and pasted what you put and now it works. But now the minus sign doesn't change back to a cross. The main issue is solved though.
  23. onclick="if (document.getElementById('plus').style.background=='black'){ document.getElementById('plus').style.background='green'; } else { document.getElementById('plus').style.background='black'; }" I click a green button with the ID of plus and it turns black, but I click it again, it doesn't turn back to green
  24. Thanks for your help. I have put it in as a function now, but it still isn't working the function comes out on the webpage source as toggleBg('plus33') which is the right number, so it should work if 'plus33' goes in the brackets. It is part of a bigger javascript, I will post that, but I can't post the whole thing, it is massive. It is $clicker btw not $count, but I've changed that. Here is the function and the onclick part. <script type="text/javascript"> function toggleBg(){ if (document.getElementById('plus').style.background=="url('/images/minus.png')"){ document.getElementById('plus').style.background="url('/images/plus.png')"; } else { document.getElementById('plus').style.background="url('/images/minus.png')"; } </script> onclick=" if (document.getElementById('rev$clicker').style.display=='block'){ document.getElementById('rev$clicker').style.display='none'; } else { document.getElementById('rev$clicker').style.display='block'; } if (document.getElementById('box$clicker').style.display=='block'){ document.getElementById('box$clicker').style.display='none'; } else { document.getElementById('box$clicker').style.display='block'; } if (document.getElementById('revb$clicker').style.display=='block'){ document.getElementById('revb$clicker').style.display='none'; } else { document.getElementById('revb$clicker').style.display='block'; } if (document.getElementById('boxb$clicker').style.display=='block'){ document.getElementById('boxb$clicker').style.display='none'; } else { document.getElementById('boxb$clicker').style.display='block'; } toggleBg('plus{$clicker}') } "/>
  25. I can't call it as a function because it is inside a PHP script and the ('plus') is really ('plus$count') if I call it as a function, the $count won't mean anything.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.