Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Hello i'm trying to echo all proxies from my sqlite database
Screenshot:
For some reason they dont output in the browser there are also no errors
When I run the sql command in a sqlite browser it works fine. (see screenshot)
$db = new SQLite3('proxies/http.db');
$results = $db->query('SELECT proxy FROM httpproxies LIMIT 25;');
foreach($results as $entry) {
echo $entry['proxy'];
}
I want it to echo all proxies, each on a new line.
try to use While insteadof foreach (you need fetchArray)
<?php
$db = new SQLite3('proxies/http.db');
$results = $db->query('SELECT proxy FROM httpproxies LIMIT 25;');
while ($row = $results->fetchArray()) {
var_dump($row);
}
?>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 13 days ago.
Improve this question
I am converting all my php scripts due to moving to a new server. I am stumped as to why $row[0] is not working.
I am correctly getting $row populated as an array, and if I run a foreach on it, I get all the values populated just fine. But if, instead, I try to directly access the first value of the array as $row[0], I get nothing. Anyone know what?
$sql = "DESCRIBE USER";
$result = $dbh->query($sql);
$count=0;
while($row = $result->fetch_assoc()) {
print $row[0]; // this prints nothing
foreach($row as $column) {
print "$column"; // this works as expected
}
} #<-- while
fetch_assoc returns your results as a key value of column names and values, so you need to look at the $row['myColumn'] to get the value.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
When i run my code it gives me extra square brackets in Response, and i want to get response without these SQUARE Brackets.
Respose which i am getting is below.
{"error":false,"message":"Login successfull","user":[{"u_id":"102","cust_name":"new","u_name":"user","cnic":"421","address":"sadaddd","cell_num":"43243","email":"n#gmail.com"}]}
Response which i want must be that: {"error":false,"message":"Login successfull","user":{"u_id":102,"cust_name":"new","u_name":"user","cnic":"421","address":"sadaddd","cell_num":"43243","email":"n#gmail.com"}}
My Code Section is below:
$user_login = $conn->prepare("SELECT u_id,cust_name,u_name,cnic,address,cell_num, email FROM users,cell_num WHERE u_name = :u_name AND password=:password AND users.u_id=cell_num.u_id_fk");
$user_login->execute(['u_name' => $u_name,'password'=>$password]);
if($user_login->rowCount() > 0){
$row = $user_login->fetchAll(\PDO::FETCH_ASSOC);
$response['user'] = $row;
//echo $row;
//print_r($row);
The square brackets means it is an array of data it's giving you rather than just one object.
Using fetchAll() will always return an array of rows matching the SELECT, if you know there is just one row, then you can use fetch() instead...
$row = $user_login->fetch(\PDO::FETCH_ASSOC);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
i just need on small info i want just add '#' to one variable and and put add thing into one variable. i am adding small php code to here please suggest me.
<?php
$email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_emial.;
echo $tag_name;
?>
but i am getting only # as output;
but my out should be "#mahesh1" if any have idea about this code please help me. thank you advanced.
there is so much spelling mistakes in the variables... try below given code
<?php $email34 = $row['email'];
$rem = '#gmail.com';
$trim_email = str_replace($rem ,'', $email34);
$tag_name ="#".$trim_email;
echo $tag_name;
?>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I've only recently started php again, this is supposed to add another game to a chess game database and it's supposed to add all squares as empty, the squares in the database are saved as i0,i1..i63, turno is true when it's white's turn, otherwise false, and the primary key is not metioned here as it's auto increment.
<?php
mysql_connect("localhost","pierostesting","");
mysql_select_db("my_pierostesting");
$query = "INSERT INTO board(";
for($i=0;$i<64;$i++){
$query.="i$i,";
}
$query.="turno) VALUES(";
for($i=0;$i<64;$i++){
$query.="'empty',";}$query.="1)";
echo $query;
if(mysql_query($query)){
echo 'nailed it';
}?>
Unaccepted } closing in your code it would be
<?php
mysql_connect("localhost","pierostesting","");
mysql_select_db("my_pierostesting");
$query = "INSERT INTO board(";
for($i=0;$i<64;$i++){
$query.="i$i,";
}
$query.="turno) VALUES(";
for($i=0;$i<64;$i++){
$query.="'empty',";
}
$query.="1)";
echo $query;
if(mysql_query($query)){
echo 'nailed it';
}?>
And the output of this code is correct query as you write
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Okay this really strange or I am missing something. When I run this very simmple PHP script on cmd I get the expected output which is 0. but when I uncomment the last two lines of code. . .nothing is displayed.
<?php
$test1 = 0;
echo $test1;
$test2 = 0;
#$test1_weight = 0:
#$test2_weight = 0;
?>
Is there some rule against declaring variables after an echo statement?
$test1_weight = 0:
--> change ":" to ";"
No there is no rule against declaring variables after an echo statement