PDO apparently has no means to count the number of rows returned from a select query (mysqli has the num_rows variable).
Is there a way to do this, short of using count($results->fetchAll()) ?
I have a form.The user enter the data ,the data will be stored in the data base.
Now,using phpmysql,i need to display the whole data present in db to front end.The user will click a particular thing and make some modifications and if,he press update the data should get into database.
Give me a snippet
http://dpaste.com/hold/178740/
Hi Everyone! I have a form where I've got three checkboxes like this:
<td>Wireless <input type="checkbox" name="services[]" value="wireless" /></td>
</tr>
<tr>
<td>Cellular <input type="checkbox" name="services[]" value="cellular" /></td>
</tr>
<tr>
<td>Security <input type="checkbox" name="services[]" value="Security" /></td>
<input type="submit" name="submit">
and then I extract($_POST), and have this code
$comServices = implode(",", $services);
but I get an error:
Warning: implode() [function.implode]: Invalid arguments passed in ..
does anyone know why Im getting this error?
Hello
Here is one script with out any errors
$url="http://yahoo.com";
$file1 = fopen($url, "r");
$content = file_get_contents($url);
$t_beg = explode('<title>',$content);
$t_end = explode('</title>',$t_beg[1]);
echo $t_end[0];
And here is the same script using a look to check multiple urls and getting errors
for ($j=1;$j<=$i;$j++) {
if ($x[$j]!=''){
$t_u = "http:".$x[$j];
$file2 = fopen($t_u, "r");
$content2 = file_get_contents($t_u);
$t_beg = explode('<title>',$content);
$t_end = explode('</title>',$t_beg[1]);
echo $t_end[0];
}
}
The error is Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in g:/
What exactly is wrong here?
So specifically in a mysql database. Take the following code and tell me what to do.
// connect to the mysql database
$unsafe_variable = $_POST["user-input"];
mysql_query("INSERT INTO table (column) VALUES ('" . $unsafe_variable . "')");
// disconnect from the mysql database
I have stored 6 records in mysql db,when i use this code each of the 6 records getting displayed in seprate drop down box,i want them to be displayed in a single drop down box.Where am i going wrong?
Any help ii be appreciated. Thnx in advance.
http://dpaste.com/hold/180077/
I get this 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 'order (total, addy, cc) VALUES ('798' , '123 sadf' , '12124123')' at line 1
$total = addslashes(($_SESSION['total']));
$addy = addslashes(($_POST['addy']));
$cc = addslashes(($_POST['cc']));
echo "$total";
echo "$addy";
echo "$cc";
mysql_query("INSERT INTO order (total, addy, cc) VALUES ('$total' , '$addy' , '$cc')") or die(mysql_error());
help plz =]
I want to convert this [email protected] to
hello@domain.com
I have tried:
url_encode($string)
this provides the same string I entered, returned with the @ symbol converted to %40
also tried:
htmlentities($string)
this provides the same string right back.
I am using a UTF8 charset. not sure if this makes a difference....
I'm trying to create an array of the next 5 working week days (Monday - Friday, excluding today). I know the working week varies around the world but this is not important for what I am trying to do.
So, for example, if today is a Wednesday, I want the dates for Thursday and Friday of the current week and Monday, Tuesday and Wednesday of the following week.
I thought this would work:
$dates = array();
for ($i = 1; $ < 6; $i ++)
{
$dates[] = date('Y-m-d', strtotime('+ '.$i.' weekday'));
}
But for today, it is giving me:
Monday 1st
Tuesday 2nd
Wednesday 3rd
Thursday 4th
Sunday 7th!
Any advice appreciated.
Thanks
Hello,
I have array
$list = array('string1', 'string2', 'string3');
Now i want to get the index of the value string2 i.e 1 and 2 for string3
All i want is the position of the strings in the array
string1 in 0
string2 in 1
string3 in 2
positions
How to get this ? i used array_search but it is no use !
please help !
Currently I'm leveraging http://developer.yahoo.com/search/content/V1/termExtraction.html which isn't ideal for performance and quality reasons. Before I embark on spending time on writing a system I wanted to see if there are any other available options that can do the trick.
using simplexml to parse a feed, but I want to grab the date of the oldest item in the feed. Does anyone know how to do it? Thanks
$rss = simplexml_load_file("http://search.twitter.com/search.atom?lang=en&q=foobar&rpp=100&page=1");
i want to replace ALL comma , into ,<space> in all address table in my mysql table.
For example,
+----------------+----------------+
| Name | Address |
+----------------+----------------+
| Someone name | A1,Street Name |
+----------------+----------------+
Into
+----------------+----------------+
| Name | Address |
+----------------+----------------+
| Someone name | A1, Street Name|
+----------------+----------------+
Thanks in advance.
When I run this code:
foreach($xml->movie as $movie) { if(isset($movie->photos)) { foreach ($movie->photos as $photo) { echo $photo." "; } echo "<hr/>"; } }
I get nice output of the actual data, e.g. a row looks like
06397001.jpg 06397002.jpg 06397003.jpg 06397004.jpg 06397005.jpg
But when I throw it in an array, it includes all the SimpleXML wrapper tags and the jpgs are not at the root of the array.
code:
foreach($xml->movie as $movie) { if(isset($movie->photos)) { $photos = array(); foreach ($movie->photos as $photo) { $photos[] = $photo; } } else $photos = ""; var_dump($photos); echo "<hr />"; }
e.g. same row looks like
array(5) { [0]= object(SimpleXMLElement)#11 (1) { [0]= string(12) "06397001.jpg" } [1]= object(SimpleXMLElement)#12 (1) { [0]= string(12) "06397002.jpg" } [2]= object(SimpleXMLElement)#13 (1) { [0]= string(12) "06397003.jpg" } [3]= object(SimpleXMLElement)#14 (1) { [0]= string(12) "06397004.jpg" } [4]= object(SimpleXMLElement)#15 (1) { [0]= string(12) "06397005.jpg" } }
Why is this happening/how can I remove this so I just get an array of the photos at root level like when I echo it?
Thanks, sorry for the single line code formatting; was messing up when I tried to paste directly with line breaks.
Hey guys,
i need a method to capitalize every first letter of a word.
This is what i got so far and it is working for almost every string...but it fails on this one "WELLNESS & RENOMME".
// method in stringModify Class
function capitalizeWords($words, $charList) {
$capitalizeNext = true;
for ($i = 0, $max = strlen($words); $i < $max; $i++) {
if (strpos($charList, $words[$i]) !== false) {
$`capitalizeNext` = true;
} else if ($capitalizeNext) {
$capitalizeNext = false;
$words[$i] = strtoupper($words[$i]);
}
}
return $words;
}
// Calling method
$stringModify->capitalizeWords("WELLNESS & RENOMME", " -&");
I hope someone can help me out...i tried for 1,5 hours now and don't have a clue. Thanks in advance for any tips or hints.
Greetz
Paulie
hi, i have wrote a script to produce an array of data but now want to display in order of score. The array outputs as follows;
[display_name] => Array
(
[0] => ACT_Web_Designs
[1] => user1_design
[2] => user2_design
)
[proffesion] => Array
(
[0] => Web Developer
[1] => web developer
[2] => Web Developer
)
[score] => Array
(
[0] => 15
[1] => 6
[2] => 15
)
[img] => Array
(
[0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic
[1] =>
[2] =>
)
so in a nutshell I am wanting it to be converted as follows;
[display_name] => Array
(
[0] => ACT_Web_Designs
[1] => user2_design
[2] => user1_design
)
[proffesion] => Array
(
[0] => Web Developer
[1] => web developer
[2] => Web Developer
)
[score] => Array
(
[0] => 15
[1] => 15
[2] => 6
)
[img] => Array
(
[0] => ./?0000=gif&0001=3fadb8c362ff39f3322909899ff14760&0002=prof_pic
[1] =>
[2] =>
)
I have been looking at asort() but cant get anything to work. any help would be much appreciated.
Hay All,
I cant seem to get my head around this dispite the number to examples i read. Basically I have a 2d array and want to insert it into MySQL. The array contains a few strings.
I cant get the following to work...
$value = addslashes(serialize($temp3));//temp3 is my 2d array, do i need to use keys? (i am not at the moment)
$query = "INSERT INTO table sip (id,keyword,data,flags) VALUES(\"$value\")";
mysql_query($query) or die("Failed Query");
Thanks Guys,
Hi,
I am trying to implement GZIP compression for my website. I copied the below code in my .htaccess file:
ExpiresActive On
ExpiresDefault A604800
Header append Cache-Control "public"
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
what happens is when I type username and password the page reloads but still the login form is displayed but session is set. When I refresh the page using ctrl + R the login form goes and the username is displayed. what will be the problem. wwaiting for ur reply.
Hi, I have the following code at the moment:
$ip = '195.72.186.157';
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML(file_get_contents('http://www.geoffmeierhans.com/services/geo-locator/locate/?ip='.$ip.'&output=xml'));
foreach($xmlDoc->getElementsByTagName('city') as $link) {
$links = array('text' => $link->nodeValue);
}
$city = $links['text'];
echo $city;
Is there a better way to get the city variable? Since there is only one tag called city a loop isn't really needed but I can't get it to work any other way
Right, bit of a head scratcher, although I've got a feeling there's an obvious answer and I'm just not seeing the wood for the trees.
Baiscally, using Solr as a search engine for my site, bringing back 15 results per page. When you click on a result, you get a detail page, that has a "Next in Results" link on it, which obviously forwards you on to the next result.
Whats the best way of doing this? I've come up with a few solutions but they're either too inpractical or just don't work.
I could store all the ids in a session array, then grab the one after the current one and put that in the link. But with possibly hundreds/thousands of results, the memory that array would need, and the performance hit of dealing with it isn't practical.
I could take the same approach and put it into the db, but I'll still have to deal with a potentially huge array when I grab them out of the db.
Or; I could do the search again, only returning the id's, and grab the one after the one we're currently looking at. I think this could be the best option? Although it does seem kind of messy, namely because of when I have to select the id thats on a different 'page' (ie the 16th, 31st etc result). Unless I pass through where it was in the results, and select from there, but that still doesn't seem like the right way to do it.
I'm really sorry if this is just complete nonsense, any help is massively appreciated as always,
Cheers guys!
hi
i want to merge to images but the problem is one image is .PNG format and second one is .JPG format and after merging the output should be .PNG format but the transparency is not appearing .plz help
Thanks
What is the correct (recommended method) for passing information to a view in a MVC environment.
Currently we use Zend Framework, where we write classes to handle specific things EG
a Book class with a save and load method to retrieve info from the DB, which is called from a particular nameAction().
What I would like to know is what is the best way to pass this information to the view, in some cases we do
$this-view-book_name = $book-getBookName();
and in other cases we do the following
$this-view-book = $book;
OR
$this-view-books = Book_Manager::getAllBooks();
and then access the object(s) properties in the view.
Information on-line suggests we try limit what access a view has to information, i.e pass them only what they need and in some cases people say its ok to pass stuff through as long as nothing is done to that information.
Regards
I like the flexibility of Dynamic SQL and I like the security + improved performance of Prepared Statements. So what I really want is Dynamic Prepared Statements, which is troublesome to make because bind_param and bind_result accept "fixed" number of arguments. So I made use of an eval() statement to get around this problem. But I get the feeling this is a bad idea. Here's example code of what I mean
// array of WHERE conditions
$param = array('customer_id'=>1, 'qty'=>'2');
$stmt = $mysqli->stmt_init();
$types = ''; $bindParam = array(); $where = ''; $count = 0;
// build the dynamic sql and param bind conditions
foreach($param as $key=>$val)
{
$types .= 'i';
$bindParam[] = '$p'.$count.'=$param["'.$key.'"]';
$where .= "$key = ? AND ";
$count++;
}
// prepare the query -- SELECT * FROM t1 WHERE customer_id = ? AND qty = ?
$sql = "SELECT * FROM t1 WHERE ".substr($where, 0, strlen($where)-4);
$stmt->prepare($sql);
// assemble the bind_param command
$command = '$stmt->bind_param($types, '.implode(', ', $bindParam).');';
// evaluate the command -- $stmt->bind_param($types,$p0=$param["customer_id"],$p1=$param["qty"]);
eval($command);
Is that last eval() statement a bad idea? I tried to avoid code injection by encapsulating values behind the variable name $param.
Does anyone have an opinion or other suggestions? Are there issues I need to be aware of?
I'd like to "grab" a few hundred urls from a few hundred html pages.
Pattern:
<h2><a href="http://www.the.url.might.be.long/urls.asp?urlid=1" target="_blank">The Website</a></h2>
I have a list of objects:
class Beer {
var $name;
var $id;
var $style;
var $brewery;
var $rate;
function getName() {
return $this->name;
}
function getID() {
return $this->id;
}
function getStyle() {
return $this->style;
}
function getBrewery() {
return $this->brewery;
}
function getRate() {
return $this->rate;
}
}
After doing some research online on how to accomplish this, this is my code:
usort($localBeersList, "cmp");
function cmp($a, $b)
{
if ($a->getRate() == $b->getRate()) {
return 0;
}
return ($a->getRate() < $b->getRate()) ? -1 : 1;
}
If I try and output my list after this I do not get anything.