plodos Posted August 27, 2008 Share Posted August 27, 2008 Problem 1 ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/wasetorg/public_html/search.php on line 177 $data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT 0,30"); while($info=mysql_fetch_array($data)) { if($info['no']=="1") { echo" {ucwords(strtolower($info['lname']))} {ucwords(strtolower($info['fname']))} "; //line 177 } } Problem 2) Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:......... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:......... while($info=mysql_fetch_array($data)) { if($info['no']=="1") { echo" {$info['lname']} {$info['fname']}"; } Some of the mysql datas are uppercase/lowercase like ERIK, Erik, erik....maybe because of that it gives "supplied argument is not a valid" worning... where $type like '%$search%' Im using like operators, if I convert all data with ucwords(), I can match the true datas.... How can I solve these problems? I didnt do it.... Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/ Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 echo" {ucwords(strtolower($info['lname']))} {ucwords(strtolower($info['fname']))} "; //line 177 Two things with that: - you can't call functions within "" quotes. - if you use array variable within "" quotes you must surround it with {} braces. <- this one is actually causing a warning You should do: echo "{".ucwords(strtolower($info['lname']))."} {".ucwords(strtolower($info['fname']))."}"; //line 177 That's assuming you want {} around last name and first name (I think you might put them by mistake) Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626760 Share on other sites More sharing options...
JonnoTheDev Posted August 27, 2008 Share Posted August 27, 2008 I dont think they are tyying to disply the {}, probably using to encapsulate the functions. Should be: echo ucwords(strtolower($info['lname']))." ".ucwords(strtolower($info['fname'])); Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626761 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 Yup. As for the second problem, try running echo mysql_error(); after your query, to display debugging information. Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626764 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 echo ucwords(strtolower($info['lname']))." ".ucwords(strtolower($info['fname']))."}, {".$info['country']." (Nat) <br>; echo ucwords(strtolower($info['university'])) <br>; I didnt apply the code Parse error: syntax error, unexpected '(', expecting ',' or '; Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626775 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 echo ucwords(strtolower($info['lname']))." ".ucwords(strtolower($info['fname']))."}, {".$info['country']." (Nat) <br>"; echo ucwords(strtolower($info['university']))." <br>"; Try to find an editor that would highlight your code. It will make spotting mistakes like this much easier Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626777 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 Thank you for all answers....It is working now.... Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626792 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 $Rows = mysql_num_rows(mysql_query("select * from person where $type like '%$search%'")) or die (mysql_error ()); Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/search.php on line 187 -----------------------and------------------ $data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT $start,$limit") or die (mysql_error ()); You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%'' at line 1 What are these problems? Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626803 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 Probably $type variable is empty (as well as $search) Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626805 Share on other sites More sharing options...
JasonLewis Posted August 27, 2008 Share Posted August 27, 2008 Make this: $Rows = mysql_num_rows(mysql_query("select * from person where $type like '%$search%'")) or die (mysql_error ()); This: $query = mysql_query("select * from person where $type like '%$search%'") or die(mysql_error()); $Rows = mysql_num_rows($query); Basically that meant that the query is most likely failing and returning a MySQL Resource ID. The second error is saying that $search is null, so make sure your variables are being set properly. Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626808 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 Im trying to using paging 0-25, 25-50 ....... first page is listing all datas 0-25, but when I click to next page....program is giving there errors?... Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626809 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 <?php include("dbconfig.php"); function title_case($title) { // Our array of 'small words' which shouldn't be capitalised if // they aren't the first word. Add your own words to taste. $smallwordsarray = array( 'of','a','the','and','an','or','nor','but','is','if','then','else','when', 'at','from','by','on','off','for','in','out','over','to','into','with' ); // Split the string into separate words $words = explode(' ', $title); foreach ($words as $key => $word) { // If this word is the first, or it's not one of our small words, capitalise it // with ucwords(). if ($key == 0 or !in_array($word, $smallwordsarray)) $words[$key] = ucwords(strtolower($word)); } // Join the words back into a string $newtitle = implode(' ', $words); return $newtitle; } $search = mysql_real_escape_string($_POST['search']); $type = mysql_real_escape_string($_POST['type']); $page = $_GET["page"]; if(empty($page) or !is_numeric($page)){ $page = 1; } $limit = 25; $query1 = mysql_query("select * from person where $type like '%$search%'") or die (mysql_error () ); $rowNumber = mysql_num_rows($query1); $pageNumber = ceil($rowNumber / $limit); $start = ($page-1)*$limit; $data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT $start,$limit") or die (mysql_error ()); while($info=mysql_fetch_array($data)) { if($info['committee_no']=="1") { echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>"; } if($info['no']=="2") { echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>"; } } if($page > 1){ $back = $page-1; echo "<p align=\"center\"><b><a href=\"search.php?page=$back\"><< Back </a>"; }else{ echo "<p align=\"center\"><b> << Back "; } echo " | "; if($page>=$pageNumber){ echo "Next >> </b></p>"; }else{ $next = $page+1; echo "<a href=\"search.php?page=$next\">Next >></a></b></p>"; } ?> Im trying to using paging 0-25, 25-50 ....... first page is listing all datas 0-25, but when I click to next page....program is giving there errors?... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%'' at line 1 I used this paging code before, i didnt face any prbblem....but now this scipts first page is showing the datas 0-25, why the second page is giving this error ???? Some of the mysql datas are uppercase/lowercase like ERIK, Erik, erik...and im trying the search with lowercase...it can be an error? Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626815 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 Check if $_POST['search'] and $_POST['type'] variables are set. Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626819 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 $_POST['search'] and $_POST['type'] is not blank.... for example im searching 'Mobile', program finds 43 rows.... First page is listing 25 records, but when I click the next page, just an error....next page must show 18 records... Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626832 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 But are they set when you go to the next page? Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626833 Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 No. next page shows nothing, just an error..... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%'' at line 1 Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626837 Share on other sites More sharing options...
Mchl Posted August 27, 2008 Share Posted August 27, 2008 Because your $search and $type variables are not set when you go from page to page. You're using links to switch between pages. Not only links are $_GET not $_POST, but your links don't even conatin these variables. Link to comment https://forums.phpfreaks.com/topic/121535-ucwordsstrtolower-and-supplied-argument-is-not-a-valid/#findComment-626838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.