[PHP-DB] Find value in array
Hello guys I'm trying to find a value which is into an array inside another array (hope it makes sense). The code: $query = select cat_code from authorxcat where author_code=$mod_author; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $query_aux = select * from categories order by cat_name; $result_aux = mysql_query($query_aux) or die(mysql_error()); while ($row_aux = mysql_fetch_array($result_aux)) { if (in_array($row_aux[cat_code],$row)) { echo trtd class=\nolink\.$row_aux[cat_name]./td tdinput type=\checkbox\ name=\.$row_aux[cat_name].\ value=\ .$row_aux[cat_code].\ checked/td/tr; } else { echo trtd class=\nolink\.$row_aux[cat_name]./td tdinput type=\checkbox\ name=\.$row_aux[cat_name].\ value=\ .$row_aux[cat_code].\/td/tr; } } Well, I'll try to explain it: The first query ($query) is supposed to find some categories codes and store them into the $row array. Then I just store all the categories codes into another array called $row_aux. Then I walk through the $row_aux array and check, in every step, if the current code is also into the $row array and according to that the output should be different. The problem is that no matter how many items there are in the $row array, the condition inside the While becomes true just once and not the number of times it should. Hope it is clear enough. Thanks in advanced for your help. *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105962 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] access DB via PHP classes
Well, what about building a basic class without any database conection in the constructor and then have a inherited class with the needed database conection? and then use whichever you need to generate the pages. You can even just have the basic class and execute some code in the constructor that connects or not to the database depending on a parameter you pass to it. As I told you before, I'm very newbie to OOP as well, but think that may work well. Hope it helps Bye *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] access DB via PHP classes
Well, I'll tell you what I do. I'm not a OOP expert so if someone feel like I'm doing it wrong I'll welcome any comment about . I've got a main class which I use to generate every page in my website (some are actually generated by inherited classes but that's the main idea). As I need a database conection for every page I write the connection threat in the main class constructor using mysql_pconnect which handles a persistent connection. So far it is workin alright for me. As I said before any comments will be welcome. Hope it helps *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Query error
Hello guys Does anybody have a clue on what wrong with the following sentence? select author_code from author where author_code not in (select author_code from authorxcat); Thanks *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Multiple select
Hello guys I need to pass multiple choices from multiple select lists. I have - select name = 'listbox1' multiple option selected value = ''Select .../option optionAP11/option optionAP12/AP14/option more options listed /select I can choose multiple items on the list, but only the last item chosen will be carried over to the final form page. How do I get I get it too carry multiple items? Thanks a lot *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Valid IP
Hello guys I know this should be asked in another list but don't want to subcribe just for a simple question. I apologise in advance if that bothers anyone. I'm trying to check valid IPs that come from a form filled by a user so I'm using the following: function valid_ip($ip) { //Check whether it is a valid IP if (ereg(^[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+$, $ip)) return true; else return false; } However it just accepts IPs such as xxx.xxx.xxx.xxx Errors arise whith IP such as xxx.xx.xxx.xxx that is every part of the IP should be 3 numbers lenght to be accepted making the function not very handy. Any idea? *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Valid IP
You're right, thanks. Shouldn't it be [0-9] for each of the elements, also? *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Can't see the results
Hi guys, it's me again. Well, I did as Peter suggested and changed my code for this: $query_cat = select author.author_names || ' ' || author.author_surnames as author_full_name from author, authorxcat where authorxcat.cat_code = $code and author.author_code = authorxcat.author_code; $result_cat = mysql_query($query_cat) or die ($mysql_error()); $num_results_cat = mysql_num_rows($result_cat) or die ($mysql_error()); while($row = mysql_fetch_array($result_cat)) { $content .= $row[author_full_name].br; } Well, it should give me the full name of 22 people but all I'm getting is a row of 22 zeros. I checked the database and in fact the data is there. Any idea of what I could be missing? Thanks a lot for your help *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Can't see the results - It works now!!!
Hello guys (again) Well, just wanted to let you know that my code is working now, at the end it worked thanks to the help of Jim and Peter. The following is the resulting code just in case anyone can make use of it. Thankyou so much. $query_cat = select concat(author.author_names,' ',author.author_surnames) as author_full_name from author, authorxcat where authorxcat.cat_code = $code and author.author_code = authorxcat.author_code; $result_cat = mysql_query($query_cat) or die ($mysql_error()); $num_results_cat = mysql_num_rows($result_cat) or die ($mysql_error()); while($row = mysql_fetch_array($result_cat)) { $content .= $row[author_full_name].br; } *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] not a valid MySQL result
Hello guys This is my first posting to the list, even though I've had some experience with C++, these are my first steps with php and mysql. Well, the thing is that I'm getting the following message: Warning: Supplied argument is not a valid MySQL result resource in /var/www/bva/new/main/colecciones.php on line 35 The code is shown below: $query_cat = select author_names || ' ' || author_surnames from author, author-cat where author_cat.cat_code = $code and author.author_code = author-cat.author_code; $result_cat = mysql_query($query_cat); $num_results_cat = mysql_num_rows($result_cat); //This is line 35 I did the same with a simpler select sentence and it worked alright, so I guess there's a problem with the select sentence but haven't been able to find it. Does anyone have an idea? Thanks a lot for your help. *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] not a valid MySQL result
Hi guys Thanks for your help. Peter was right I had an error in the sentence, I worked it out but still the same error came up. The mysql_error() function doesn't return any thing. Any idea? Thanks a lot. Hi Couple of points, you probably have an SQL error, I use echo $query; echo 'br'.mysql_error(); which shows the query and the error you use 'author-cat' in the table name and 'author_cat' and 'author-cat' in the where clause which will throw an error. *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Can't see the results
Hello guys Thanks to all those you helped me with y the question I made before (not a valid MySQL result) it's working now. Now, I want to display the result of my search with the following code: if($code){ $query_cat = select author.author_names || ' '|| author.author_surnames as full_name from author, authorxcat where authorxcat.cat_code = $code and author.author_code = authorxcat.author_code or die($mysql_error()); $result_cat = mysql_query($query_cat); $num_results_cat = mysql_num_rows($result_cat); for ($i=0; $i $num_results_cat; $i++) { $row = mysql_fetch_array($result); $content .= $row; /* $content .= htmlspecialchars(stripslashes($row[author_names])) . .htmlspecialchars(stripslashes($row [author_surnames])).br;*/ } } But I just get the following: ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray I also tried to do it commenting the $content .= $row; and uncommenting the lines that are commented in the code but I just get a blank page. What am I doing wrong? Thanks a lot for your help. *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php