PHP - Count() Issues, Similar To Odesk.com Dmoz.org
Hello everybody,
I'm trying to write some code similar to Odesk.com or DMOZ.ORG. I need to count the number of listings in each category. Look here "http://ibatty.org/browse.php" to get a better idea of what I'm doing. That is the page I'm trying to add this function to. I've been having major issues with the COUNT function. Code: [Select] $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='billboards'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) { echo $row[COUNT(category)]; } As you can see this works, but I'm trying to add State, Area code and Zip functuality to search through the data more precisely. This has been giving me problems though and the way I currently have it setup . . . I'd have 25+ SELECT COUNT() querys going on 1 page. (I don't know if that is very good?) 5$ via paypal to whoever can help me solve this. If I did not explain what I needed very well, please ask questions for me to clarify. Thank you in advance Similar TutorialsHow to COUNT the number of records (pulled from a db)which contains the word "APPROVED". This code doesn't work though. $result1; $result2; $result3; $approvedApplicants = COUNT($result1=='Approved', $result2=='Approved', $result3=='Approved') echo ($approvedApplicants) I have an XML document that id decrypted and shown onto a table. At the bottom of the page, I'm trying to have it count up one Code: [Select] foreach($Data as $Types) // loop through book foreach($Types as $Colors) // loop through book { print_r(count($Colors->Color)); } There are 4 colors, blue, green, red, yellow. Blue is listed 7 times, green is 3, red is 8, and yellow is 4 times. What I expect it to print is: 7 3 8 4 Instead, it's printing this: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 If I was to just do the print function without count, it lists like this: blue red blue red green yellow blue red yellow red red green yellow yellow blue blue green blue yellow blue red red blue red My end-goal of this code is to get it to print this: Blue: 7 Green: 3 Red: 8 Yellow: 4 Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles im trying to run a query which will get posts from the database that have tags similar to the current ones. Unfortunatly the echoed result isnt displaying as it should. $query = $link->query("SELECT t.*, p.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) WHERE t.t_name = '".decode_url($_GET['t_name'])."' LIMIT 1") or die(print_link_error()); $row = $query->fetch(PDO::FETCH_ASSOC); $tag_query = $link->query("SELECT p_name FROM ".TBL_PREFIX."posts WHERE MATCH (p_tags) AGAINST ('".$row['p_tags']."' IN BOOLEAN MODE) ")or die(print_link_error()); $result = $tag_query->fetch(); foreach($result as $key => $value) { echo 'Name = '.$result[$key]['p_name'].'<br />'; } i have done a dump of result and it shows: Code: [Select] $ => Array (2) ( ['p_name'] = String(12) "File Updates" ['0'] = String(12) "File Updates" ) but there should only be one item in this array(p_name). I dont know where the second is coming from. The query has pulled the right results, it just isnt displaying it right. How can I check if an array contains two items that are the same? For example ("apples", "bananas", "oranges") returns false But ("apples", "bananas", "bananas") returns true Hello, I am looking for a push in the right direction. I would like to be able to view a website that is duplicated on many servers by specifying the IP address. Similar to how one would use the hosts file. I can do this using netcat nc 1.2.3.4 80 Host: example.com GET /contact-us.html <CR><CR> Can someone tell me how I would go about porting this to PHP? I would just like to set up a small page on my webserver where I can enter the domain and IP address and have the page displayed back to me. Thanks Colin hi My first language is not english so i hope you bear it i am new to php am am making my shopping Cart as my web engineering course i have made everything i all want to know how to i show similar products when a user click on any product details it open new page and shows a detail of that page i want to show similar products list below to details so can any tell me how to do it plzz kindly see the pic in atttachment i have posted snap shop of my page i put similar product statically i want to show it dynamically from tha data base kindly answer please regards I'm pretty sure there isn't, but I was wondering if there was a php function that would return partial matches similar to MySQL's LIKE, I've been searching for a while and haven't found one. If not, is there a class or something that someone knows of that will accomplish a like of search or a string comparison? I want to be able to compare two variables and return one of three results - Exact Match, Partial Match, No Match. I suppose regex may do the trick but I'm a complete novice when it comes to regex and I have no idea where to even begin. Thanks for any suggestions. Hi Folks, i have been at this for ages and its now depressing me as i cannot figure out why i cant get it to work. I am using a re-hashed version of a facebook style wall post system where it limits the amount of replies, you click a button and gets the next set and so on until there are no more results to get. The original script runs ok but is not really suitable for what i need So to my script which is based loosley on the same principal. Ok i have a veiwmember.php page which uses pagination to limit the amount of wall posts to 5. I have included the various javascript files jquery and another which is needed. The function used is this one: Code: [Select] <script type="text/javascript" src="jquery.livequery.js"></script> <script type="text/javascript" src="jquery-1.2.6.min.js"></script> <script type="text/javascript"> //more records show $('a.more_records').livequery("click", function(e){ var next = $(this).attr('id').replace('more_',''); $.post("data.php?show_more_post="+next, { }, function(response){ $('#bottomMoreButton').remove(); $('#posting').append($(response).fadeIn('slow')); }); }); </script> The php code in veiwmember.php that gets the wall posts is: Code: [Select] Pagination code here <?php $getwallposts= ("SELECT * FROM wallposts WHERE recipientid='$memberid' ORDER BY id DESC LIMIT $offset, $rowsperpage"); $result = mysql_query($getwallposts,$con); while ($row2 = mysql_fetch_assoc($result)) { $messageid= $row2['id']; $senderid= $row2['senderid']; $wallpost= $row2['wallpost']; $timesent= $row2['timesent']; $timestamp = strtotime($timesent); $likes= $row2['likes']; $getname= ("SELECT fname, lname, image1 FROM memocp WHERE unid='$senderid'"); $nameresult= mysql_query($getname,$con); while ($rowws = mysql_fetch_array($nameresult)) { $fname= $rowws['fname']; $lname= $rowws['lname']; $wallpostprofilethumb= "{$rowws['image1']}"; if (empty($wallpostprofilethumb)) {$wallpostprofilethumb= "noimage.png";} } ?> <div class="wallpost"><div class="from"><div class"profilethumb"><img src="profilethumb/<?php echo $wallpostprofilethumb; ?>"></div><a href="veiwmember.php?membid=<?php echo "$senderid"; ?>"><?php echo "$fname $lname"; ?></a></div><div class="postbody"><?php echo txt2link($wallpost) ?><div class="timesent"><?php echo date('l jS F Y @ H:i a', $timestamp); ?></div></div><div class="likes"><form action="like.php" method="post"><?php if (isset($_GET['currentpage'])) {$currentpage= $_GET['currentpage']; echo "<input name=\"currentpage\" type=\"hidden\" value=\"$currentpage\">";} ?><input name="messageid" type="hidden" value="<?php echo "$messageid"; ?>"><input name="base" type="hidden" value="<?php echo "$memberid"; ?>"><input name="like" type="image" src="ima/like.jpg"><?php echo " $likes people like this"; ?></form></div></div> <?php include_once('data.php'); ?> <?php } rest of pagination The pagination sort of works, but only displays one result per page when it should show 5 results plus how ever many replies, but i can sort that out later, would prefer to get the replies working first. You will see that data.php is included which gets the replies to the wall posts. It should limit the amount of replies shown to five, and then if there is more, it will show a link to get more. If that link is clicked it should get the next five results and show them. However it shows the first five and the link if there are more results, but if the link is clicked, nothing happens. data.php Code: [Select] require ("database.php"); $next_records = 5; $show_more_button = 0; if(isset($_REQUEST['show_more_post'])) // more posting paging { // button has been clicked so we need to get next set of results $next_records = $_REQUEST['show_more_post'] + 5; $result = mysql_query("SELECT * FROM wallreplies2 WHERE messageid='$messageid' ORDER BY wallreplyid DESC limit ".$_REQUEST['show_more_post'].", 5"); // see if there are any more replies to get $check_res = mysql_query("SELECT * FROM wallreplies2 order by wallreplyid DESC limit ".$next_records.", 5"); $show_more_button = 0; // button in the end $check_result = mysql_num_rows($check_res); if($check_result > 0) { // if there any more results counted the button needs to be shown $show_more_button = 1; } } // if the button hasnt been clicked we need to get the first results else { // lets count the number of results that exist $countreplies= mysql_query("SELECT * FROM wallreplies2 WHERE messageid='$messageid'"); $countresult= mysql_num_rows($countreplies); // if there are more than 5 results if ($countresult > 5) { // the button needs to be shown $show_more_button = 1; } else { // if there are 5 or less replies in total, dont show the button $show_more_button = 0;} //there are only 5 or less replies to get so get the first results $result = mysql_query("SELECT * FROM wallreplies2 WHERE messageid='$messageid' ORDER BY wallreplyid DESC limit 0,5"); } //$replyresult = mysql_query($result,$con); while ($roww = mysql_fetch_array($result)) { $wallreplyid= $roww['wallreplyid']; $sendid= $roww['senderid']; $wallreply= $roww['wallreply']; $time= $roww['timesent']; $Timestamp = strtotime($time); $like= $roww['likes']; $getreplynames = ("SELECT fname, lname, image1 FROM memocp WHERE unid='$sendid'"); $nameresults = mysql_query($getreplynames,$con); while ($roww = mysql_fetch_array($nameresults)) { $fnames= $roww['fname']; $lnames= $roww['lname']; $wallreplyprofilethumb= "{$roww['image1']}"; if (empty($wallreplyprofilethumb)) {$wallreplyprofilethumb= "noimage.png";} } ?> <div class="wallreplies" id="record-<?php echo"$wallreplyid"; ?>"> <div class="wallreplywrap"> <div class="wallfrom"> <div class"profilethumb"><img src="profilethumb/<?php echo $wallreplyprofilethumb; ?>"></div> <a href="veiwmember.php?membid=<?php echo "$sendid"; ?>"><?php echo"$fnames $lnames"; ?></a> </div> <div class="wallmessbody"><?php echo txt2link($wallreply) ?></div> <div class="timesent"><?php echo date('l jS F Y @ H:i a', $Timestamp); ?></div> <div class="likes"><form action="like2.php" method="post"><?php if (isset($_GET['currentpage'])) {$currentpage= $_GET['currentpage']; echo "<input name=\"currentpage\" type=\"hidden\" value=\"$currentpage\">";} ?><input name="messageid" type="hidden" value="<?php echo "$wallreplyid"; ?>"><input name="base" type="hidden" value="<?php echo "$memberid"; ?>"><input name="like" type="image" src="ima/like2.jpg"><?php echo " $like people like this"; ?></form> </div> </div> </div> <?php } if($show_more_button == 1){ echo "<div class=\"bottomMoreButton\"> <a id=\"more_$next_records\" class=\"more_records\" href=\"javascript: void(0)\">Get more replies</a> </div>"; }?> <div class="wallreply"> <form action="wallreply.php" method="post"> <input name="sendrid" type="hidden" value="<?php echo "$loginuniqid"; ?>"> <input name="messageid" type="hidden" value="<?php echo "$messageid"; ?>"> <input name="base" type="hidden" value="<?php echo "$memberid"; ?>"> <?php if (isset($_GET['currentpage'])) {$currentpage= $_GET['currentpage']; echo "<input name=\"currentpage\" type=\"hidden\" value=\"$currentpage\">";} ?> <textarea class="newwallpostreply<?php echo $i++ ; ?>" name="wallreply" autocomplete="off" maxlength="1000" placeholder="Reply"></textarea> <span class="wallreply-holder<?php echo $p++; ?>"> <div class="button_block"> <input type="submit" class="post" value="Post"> <input type="submit" class="cancel" value="Cancel"> </div> </span> </form> </div> I know its a lot of info there, but if anyone can see the problem i would be greatful. Hello, I need to be able to find what is inbetween 2 values in a string of text. For example, <?php $string="Hello and welcome to the site. Click [link]welcome.php[/link] here to continue to the site"; ?> So I need some method of searching the string to see what values are in between the [link] and [/link] which I will then deal with in my own way. I have a feeling that I could do this with explode, but I'm not really sure. Any advice? Thanks in advance This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=350182.0 are all of the following same, or some same or all different: $variable="" $variable=0 $variable=NULL and which of the above will satisfy if(empty($variable)) { blah!; } I have a brain twister in a script i'm working on. It have a multidimensional array that hold values to populate a google charts js script. To make it work as I plan I need to merge the data from similar arrays together. I'll give an example and hopefully it will make more sense. Also, this page is being loaded over ajax so, the faster/smaller the better. Example Array: Code: [Select] Array ( [0] => Array ( [item] => 1 [quant] => 2 [price] => 12.5 [day] => 18 [onl] => ) [1] => Array ( [item] => 1 [quant] => 2 [price] => 12.5 [day] => 18 [onl] => ) [2] => Array ( [item] => 1 [quant] => 5 [price] => 12.5 [day] => 17 [onl] => 1 ) [3] => Array ( [item] => 1 [quant] => 12 [price] => 12.5 [day] => 19 [onl] => 1 ) [4] => Array ( [item] => 1 [quant] => 4 [price] => 12.5 [day] => 21 [onl] => ) ) So since array 0 and 1 both have data from sales on the 18th for the same item I would want to merge them into a single array and leave all others in the parent array the same. I apologize in advance if this doesn't make sense, I've been working too many hours. X| If anyone knows of a good solution for this or perhaps a better approach, that would be great. Thank You, E I need to display multiple files that have a similar file name, but there are timestamps added to the filename once its been modified. What could I use in PHP to display all these files? Right now I use a $path variable that looks into a SQL table to build the path to the folder that the files reside in.. ELSEIF($Recordmyrow['Applicatio'] == "pdf file") { IF($securityvalue != "P"){$display = false;} IF(file_exists(substr($path, 5))){} ELSE{$column4 = "<A href='javascript:mbox();'>UNAVAILABLE</A>";} } So there is a file called file1.pdf then another one called file1.mmddyyyy.pdf My code shows file1.pdf but not file1.mmddyyyy.pdf Is there some kind of wildcard I can use to get it to show all the files if they exist? I am building online dictionary with php. The following code allows the user to search a word and display the definition results from the database. The problem is the user has to input the identical words only. If the words are not exactly similar to the database words it returns error message. But in this case I need it to give a suggestion along with the error message based on the few beginning words of the submitted word. eg. if the user type a word "suggestion", and the word "suggestion" is not available in the database .... instead of just the error message to also search and include other stored data closer to the submitted word ... like "TRY the word SUGGEST". can any one help me on this please. Thank you in advance. here is the code Code: [Select] <?php $script = $_SERVER['PHP_SELF']; if(isset($_POST['sbm']) && isset($_POST['word']) ) { submited(); } else { show_form(); } function show_form() { ?> <p><center> Type <span style='font-weight:bold;'>ENGLISH</span> word Only! <span style='font-weight:bold;'>SPELL IT CORRECTLY!!!.</span></center></P> <p><center>Search</center></p> <center><form name=frm method=POST action="<?php echo $script ?>"> <p><input type=text name="word"><br /></p> <p><input type=submit name="sbm" value="Submit"> </form> </center></p> <?php } function submited() { require("dbconn.inc"); $word=$_POST['word']; $sql="select * from words where eng like '".mysql_real_escape_string($word)."'"; $result=mysql_query($sql,$link); // I assume $link is defined in dbconn.inc if(@mysql_num_rows($result)!=0) { $rows=mysql_fetch_array($result); $am=$rows["am"]; echo("<center>The Word <h1><b>$word</b></h1> in Am is : <h1><b>$am </b></h1><br></center>"); } else { echo("<center><span style='font-weight:bold;color:#FF0000;'>Could not find it! Check the spelling and try again !!</span></center>"); } // The connection will close automatically since // this is near the end of the script. mysql_close($link); show_form(); } ?> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=310618.0 |