HDFilmMaker2112
-
Posts
547 -
Joined
-
Last visited
Never
Posts posted by HDFilmMaker2112
-
-
Looks like you have extra closing brackets for an if/elseif/else statement somewhere.... Can't really help without seeing code.
-
$product_id=$_GET['product']; $sql500="SELECT * FROM $tbl_name3 WHERE product_id='$product_id'"; $result500=mysql_query($sql500); $num_rows500=mysql_num_rows($result500); while($row500=mysql_fetch_array($result500)){ extract($row500); $review_product_rating_total=$review_product_rating; //What do I do here? } $average_rating=$review_product_rating_total/$num_rows500;
I need a way to take a column of product ratings (0-5 in 1/2 increments), add them together, and divide by the number of rows taken from the database. I know how to get the number of rows with mysql_num_rows. But how would I add together the data from database?
-
Need to see your connection to the DB and DB Select statement.
-
The problem is that you are running two distinct queries, one of which is a loop on the results of the first query. You apparently have multiple results from $tbl_name2 that are associated with the same record in $tbl_name. You should NEVER run queries in loops. In this case you should be doing a JOIN between the two tables along with a GROUP BY to only get the unique values.
EDIT: This should get you started
$likeValues = "$tbl_name2.keyword LIKE '%" . implode("%' OR $tbl_name2.keyword LIKE '%", $keywords) . "%'" $query = "SELECT * FROM $tbl_name JOIN $tbl_name2 USING(product_id) WHERE $likeValues GROUP BY product_id";
Works perfectly, thanks a ton. Never used JOIN before, definitely helps to see in application that I'm actually working on to understand how it works.
-
Just finished a search script. However, when type two keywords it will return duplicate entries:
elseif(isset($_GET['search'])){ $search=$_POST['search']; $search=str_replace(" ", ".", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])){ $search=$_GET['q']; $keywords=explode(".",$search); $sql10000="SELECT product_id FROM $tbl_name2 WHERE keyword LIKE '%" . implode("%' OR keyword LIKE '%",$keywords) . "%'"; $result10000=mysql_query($sql10000); if(mysql_num_rows($result10000)==0){ $content='<div class="center">Search found no results.</div>'; } else{ while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); while($row15000=mysql_fetch_array($result15000)){ extract($row15000); $content.=$product_name; } } } }
I have 3 products:
Test2 - microphone
Test3 - audio, microphone
Test123 - audio
When you search "audio" you get:
Test3, Test123
When you search "microphone" you get:
Test2, Test3
When you search "audio microphone" you get:
Test2, Test3, Test3, Test123
with Test3 being a duplicate.
Is there anyway to correct this? I tried SELECT DISTINCT * FROM, but there's no difference in the results returned, from what I have now.
-
Is your first query executing?
Nope, that would be way, the first query is what actually does the search look-up so.... Moved it outside the first while and working perfectly now.
Thanks.
-
Well turned on error reporting and all I'm getting is notices that I have an Undefined Index and that the Content variable is undefined (because it's being called but nothing's a signed to it, for whatever reason.
The page is actually displayed properly when the keyword exists, just when there are no results returned does it not show anything.
-
That is how it should work, as the while statement will never run, being that it will return false on row 0.
You MUST put the mysql_num_rows() function BEFORE the while statement.
That's what I figured... was just to lazy to change it to try it myself.
EDIT: Just tried it, still a blank page.
while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); if(mysql_num_rows($result15000)==0){ $content='<div class="center">Search found no results.</div>'; } else{ while($row15000=mysql_fetch_array($result15000)){ extract($row15000); $content.=$product_name; } } }
-
while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); while($row15000=mysql_fetch_array($result15000)){ extract($row15000); if(mysql_num_rows($result15000)==0){ $content='<div class="center">Search found no results.</div>'; } else{ $content.=$product_name; } } }
The above does not display the $content variable when there are no rows returned, just comes up with a blank page. Works fine when there are results returned.
-
Well, anyway I changed it to "."
Working now. Thanks for the help.
Curious to know how Google, Bing, and a lot of other major retailers manage to use "+" in their search queries to hold together the string.
-
The "+" character has special meaning when used in a URL. It will replaced by a space. Pick another character for your deliminator, such as a "~" or "`" or "|" or any character that you're not expecting to be in a keyword.
Ken
The reason I was trying to use "+" is because I see it all the time in search engine URLs, and a lot of other stores.
-
What is the value of the variable $keywords?
Post the result of
<?php echo '<pre>' . print_r($keywords,true) . '</pre>'; ?>
If $keywords is an array, you can create the query like this:
<?php $q = "SELECT product_id FROM $tbl_name2 WHERE keyword like '%" . implode("%' or keyword like '%",$keywords) . "%'"; ?>
Ken
tried this and get the '%test test2 %' problem as well. The URL of the page has q=test+test2. Meaning it should be pulled into the explode and be placed into an array of $keywords("test","test2")... if I'm not mistaken.
echo '<pre>' . print_r($keywords,true) . '</pre>';
That returns:
Array
(
[0] => test test2
)
On my computer running Windows XP with FireFox
on my windows 7 comp with FireFox it returns something different (weird since the computer shouldn't be doing any processing):
Array
(
[0] => test
)
-
Try this. I haven't executed it, but it should work... I think.
<?php elseif(isset($_GET['search'])) { $search = $_POST['search']; $search = str_replace(" ", "+", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])) { $search = $_GET['q']; $keywords = explode("+", $search); $sql10000 = "SELECT product_id FROM $tbl_name2 WHERE "; } foreach($keywords as $query10000) { $sql10000 .= "keyword LIKE '%".$query10000."%' OR "; } $sql10000 = substr($sql10000,0,(strLen($sql10000)-3)); $content = $sql10000; ?>
Alright, that got rid of the "Array" and placed it with the data, but it's now come up as
'%test test2%'... Don't get why, I've had this problem all day with it not add the closing % after test with the closing single quote and then opening % and single quote for test2.
-
elseif(isset($_GET['search'])){ $search=$_POST['search']; $search=str_replace(" ", "+", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])){ $search=$_GET['q']; $keywords=explode("+",$search); $sql10000="SELECT product_id FROM $tbl_name2 WHERE "; while($query10000=each($keywords)){ $sql10000.="keyword LIKE '%".$query10000."%' OR"; } $sql10000=substr($sql10000,0,(strLen($sql10000)-3)); $content=$sql10000;
That is returning this:
SELECT product_id FROM keywords WHERE keyword LIKE %Array%
For some reason it's showing "Array", it should be looping through the keywords array.
-
I dont understand very well your problem. Just check if the user in the sesion is admin or not and do that, no?
You have a bit of a security hole by doing that... If the actual user steps away from their computer, and somebody else comes along, they can click into the admin panel then without need to validate they are indeed that person.
-
Create another form with separate SESSION variable, and populate the Username field (if there is one) with the Username set from the original form. So all they need to do is re-type in their password. That's what most sites do when you go in to edit account settings. And then you can kill the second session when they log-out of the admin panel, but they stay logged in to general area.
-
Use the function parse_str
<?php $str = 'api=somerandomkeyhere&user=someuser&password=somehashvaluehere&type=somethingelse'; parse_str($str,$ary); print_r($ary); ?>
Ken
Thanks I did not know such a simple function existed. This was exactly what I was looking for.
-mme
Neither did I. Much simpler than my method.
-
$strings=explode("&","string here")
Gets you:
$strings array("api=somerandomkey", "user=someuser", "ect.")
foreach($strings as $string){ $string=explode("=",$string); }
$string array("api","somerandomkey", "user", "someuser", "ect.")
$string[0]=$string[1];
$string[0] could also be $string["api"]
-
The below is returning:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/zyquo/public_html/ghosthuntersportal.com/pages.php on line 39
Line 39 is, while($row10000=mysql_fetch_array($result10000)){
elseif(isset($_GET['q'])){ $search=$_GET['q']; $keyword=explode("+",$search); $keywords=implode(",",$keyword); $sql10000="SELECT product_id FROM $tbl_name2 WHERE keyword IN($keywords)"; $result10000=mysql_query($sql10000); while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); while($row15000=mysql_fetch_array($result15000)){ extract($row1500); $content=$product_id; } } }
-
alright, just making sure I'm on the right track here:
elseif(isset($_GET['search'])){ $search=$_GET['search']; $keyword=explode(" ",$search); $keywords=implode(",",$keyword); $sql10000="SELECT product_id FROM $tbl_name2 WHERE keyword IN($keywords)"; $result10000=mysql($sql10000); while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; mysql($sql15000); } }
-
I'm looking to know the best way to process a search query that has multiple words in the search:
elseif(isset($_GET['search'])){ $search=$_GET['search']; $keyword=explode(" ",$search); //database query }
Should I do a while loop query the database for each keyword?
-
Never mind...
<a href="./admincp.php?do=delete&id='.$product_id.'">Delete Product</a>
should have been:
<a href="./product_process.php?do=delete&id='.$product_id.'">Delete Product</a>
Basically I was trying to process the product_id with the wrong file.
Too early to be coding...
-
I'm trying to pass a product_id through a URL, to delete the product from the database:
<a href="./admincp.php?do=delete&id='.$product_id.'">Delete Product</a>
My issue is the code below is not getting the product_id from the URL.
elseif($_GET['do']=="delete"){ if(isset($_GET['id'])){ $product_id=$_GET['id']; $sql5000="DELETE FROM $tbl_name WHERE product_id=".$product_id.""; mysql_query($sql5000); $sql5500="DELETE FROM $tbl_name2 WHERE product_id=".$product_id.""; mysql_query($sql5500); header("Location: ./admincp.php?deleted=yes"); } }
-
Alright, the only thing I can think of is concatenate the $cart variable at the beginning of the script and see what happens.
$cart .= $_SESSION['cart'];
It seems like since you're getting session data into $cart, basically after looping through each time, it's overwriting stuff.
Adding together values from database
in PHP Coding Help
Posted
$total = $total + $review_product_rating;