Hi! You could try with:
$url = get_field('url');
if(FALSE === $url)
{
# code for empty value
}
else
{
# code for assigned value
}
See: https://www.advancedcustomfields.com/resources/code-examples/#using-conditional%20statements
Hi! You could try with:
$url = get_field('url');
if(FALSE === $url)
{
# code for empty value
}
else
{
# code for assigned value
}
See: https://www.advancedcustomfields.com/resources/code-examples/#using-conditional%20statements
Hello,
I just saw your question, so according to FB best practises:
Use images that are at least 1200 x 630 pixels for the best display on high resolution devices. At the minimum, you should use images that are 600 x 315 pixels to display link page posts with larger images. Images can be up to 8MB in size.
If your image is smaller than 600 x 315 px, it will still display in the link page post, but the size will be much smaller.
We've also redesigned link page posts so that the aspect ratio for images is the same across desktop and mobile News Feed. Try to keep your images as close to 1.91:1 aspect ratio as possible to display the full image in News Feed without any cropping.
And last:
The minimum image size is 200 x 200 pixels. If you try to use an image smaller than this you will see an error in the Sharing Debugger.
Source: https://developers.facebook.com/docs/sharing/best-practices#images
Check arp-scan -ln
it outputs something like this:
> arp-scan -ln
Interface: wls1, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.0.1 00:c0:9f:09:b8:db QUANTA COMPUTER, INC.
192.168.0.5 00:02:a5:90:c3:e6 Compaq Computer Corporation
192.168.0.87 00:0b:db:b2:fa:60 Dell ESG PCBA Test
192.168.0.90 00:02:b3:06:d7:9b Intel Corporation
192.168.0.153 00:10:db:26:4d:52 Juniper Networks, Inc.
192.168.0.191 00:01:e6:57:8b:68 Hewlett-Packard Company
192.168.0.196 00:30:c1:5e:58:7d HEWLETT-PACKARD
7 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8.1: 256 hosts scanned in 1.628 seconds (157.25 hosts/sec). 7 responded
And you could simply parse the output. But I'm not sure if there is a version for Windows platforms. Some info here:
In this very specific case, because $ID is expected to be an integer, you could use exec()
which returns the number of affected rows by the statement or something that evaluates to boolean FALSE (if something goes wrong) but you have to properly sanitize the variable.
$ID = filter_input(INPUT_GET, 'ID', FILTER_VALIDATE_INT);
if(FALSE !== $ID)
{
$update = $db->exec("UPDATE table SET count = count + 1 WHERE id=".$ID);
if(FALSE === $update)
{
// log the error, kill the script, etc.
}
else
{
// successful update
}
}
else
{
// $ID is not valid
}
In case of strings, instead, the filter function is not enough, because sending something like 0 OR 1=1
would be valid and expose your query to an SQL injection attack.
I prefer to have few extra lines of code and go with prepared statements.
Besides, in PDO you can send the values as an array, in the execute()
method:
$stmt->execute([':ID' => $ID]);
Hi,
it happens because getDB() is using PDO and in the script you are using MySQLi. Fix it and it should work.
I was supposing the $_POST['Net']
arrays to hold float values, not file names. Anyway you could write:
$files = [];
$products = [];
while($rowProduct = mysql_fetch_array($productSQL))
{
$products[] = $rowProduct['POProductNet'];
}
if(TRUE === isset($_POST['Net']) && TRUE === is_array($_POST['Net']))
{
$files = array_map('basename', $_POST['Net']);
$diff = array_diff_assoc($products, $files);
if(count($diff) > 0)
{
// write data to db
}
}
Here I'm just using the array functions, instead of the loops, it's just a choice. You can go with loops.
But if $_POST['Net']
is supposed to always be an array, then I would check it in the sanitizing step, not after the query to the database. So it would look like more:
$net = filter_input(INPUT_POST, 'Net', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
if(FALSE !== $net)
{
$files = array_map('basename', $net);
$products = [];
// select query the database
// populate the $products array
// compare with $files
}
Hi,
you could use array_diff_assoc()
:
<?php
$sql = [25.00, 25.00, 50.00, 82.00, 120.00, 205.00];
$post = [25.00, 50.00, 50.00, 80.00, 120.00, 205.00];
print_r(array_diff_assoc($post, $sql));
Returns:
Array
(
[1] => 50
[3] => 80
)
So you can manage the array through the index key of the array. But what is the goal of this compare?
You could use the RecursiveDirectoryIterator()
something like in this comment:
More precisely like this:
<?php
$path = dirname(__DIR__);
$dir_iterator = new RecursiveDirectoryIterator($path
, FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($dir_iterator
, RecursiveIteratorIterator::LEAVES_ONLY
, RecursiveIteratorIterator::CATCH_GET_CHILD);
foreach($iterator as $file)
if(TRUE === $file->isReadable())
echo $file . PHP_EOL;
Hi,
look, this hex dump suggests it could be C++:
0007e0a0 72 20 61 72 67 75 6d 65 6e 74 73 0d 0a 00 00 00 |r arguments.....|
0007e0b0 52 36 30 30 32 0d 0a 2d 20 66 6c 6f 61 74 69 6e |R6002..- floatin|
0007e0c0 67 20 70 6f 69 6e 74 20 6e 6f 74 20 6c 6f 61 64 |g point not load|
0007e0d0 65 64 0d 0a 00 00 00 00 4d 69 63 72 6f 73 6f 66 |ed......Microsof|
0007e0e0 74 20 56 69 73 75 61 6c 20 43 2b 2b 20 52 75 6e |t Visual C++ Run|
0007e0f0 74 69 6d 65 20 4c 69 62 72 61 72 79 00 00 00 00 |time Library....|
0007e100 0a 0a 00 00 52 75 6e 74 69 6d 65 20 45 72 72 6f |....Runtime Erro|
0007e110 72 21 0a 0a 50 72 6f 67 72 61 6d 3a 20 00 00 00 |r!..Program: ...|
0007e120 2e 2e 2e 00 3c 70 72 6f 67 72 61 6d 20 6e 61 6d |....<program nam|
0007e130 65 20 75 6e 6b 6e 6f 77 6e 3e 00 00 00 00 00 00 |e unknown>......|
And this:
0008ead0 46 53 4f 55 4e 44 20 50 72 69 6d 61 72 79 20 4d |FSOUND Primary M|
0008eae0 69 78 42 75 66 66 65 72 00 00 00 00 43 3a 5c 64 |ixBuffer....C:\d|
0008eaf0 65 76 5c 66 6d 6f 64 33 36 30 73 72 63 5c 73 72 |ev\fmod360src\sr|
0008eb00 63 5c 66 73 6f 75 6e 64 2e 63 00 00 43 3a 5c 64 |c\fsound.c..C:\d|
0008eb10 65 76 5c 66 6d 6f 64 33 36 30 73 72 63 5c 73 72 |ev\fmod360src\sr|
0008eb20 63 5c 66 73 6f 75 6e 64 5f 73 61 6d 70 6c 65 2e |c\fsound_sample.|
0008eb30 63 00 00 00 4d 65 6d 6f 72 79 20 66 69 6c 65 00 |c...Memory file.|
points to http://www.blitzbasic.com/ tools. See if they can help you.
Hi,
from the documentation the strtotime()
function you can read:
Parse about any English textual datetime description into a Unix timestamp
And it expects:
int strtotime ( string $time [, int $now = time() ] )
The $stockdate
is a DateTime object, not a string. So try by submitting the string:
date('l F d, Y', strtotime($stockdate->date));
Or follow the DateTime library:
print $stockdate->format('l F d, Y');
Docs:
Spaces in URLs can be represented by %20
or by +
, it depends on the browser and by the enctype attribute of the form tag.
Your script can receive requests like these:
term=abc++++
term=abc%20%20%20%20
Which in your code equals to:
string(7) "abc "
So, instead of $searchTerm = $_GET['term'];
do:
$searchTerm = trim(filter_input(INPUT_GET, 'term', FILTER_SANITIZE_STRING));
And the script will process the intended input:
string(3) "abc"
Note, in this case you don't need to use urldecode()
as superglobals are already decoded. Also, you should query the database through prepared statements.
Ok, the blank list of results happens because JQuery expects to receive label
and/or value
as index keys of the result set.
Multiple types supported:
Array: An array can be used for local data. There are two supported formats:
- An array of strings:
[ "Choice1", "Choice2" ]
- An array of objects with label and value properties:
[ { label: "Choice1", value: "value1" }, ... ]
The label property is displayed in the suggestion menu. The value will be inserted into the input element when a user selects an item. If just one property is specified, it will be used for both, e.g., if you provide only value properties, the value will also be used as the label.
Source: http://api.jqueryui.com/autocomplete/#option-source
So change desc1
to label
and should work fine. I was testing with a custom table which had a label
column, so the issue didn't show up to me.
Do:
<script type="text/javascript">
$(function() {
$("#party").autocomplete({
minLength: 0,
source: "autocomplete.php",
focus: function(event, ui) {
$("#party").val(ui.item.label);
$("#code").val(ui.item.code);
return false;
},
select: function(event, ui) {
$("#party").val(ui.item.label);
$("#code").val(ui.item.code);
return false;
}
})
});
</script>
And in the PHP side:
$i = 0;
while($row=sqlsrv_fetch_array($select))
{
$data[$i]['code'] = $row['code'];
$data[$i]['label'] = $row['desc1'];
$i++;
}
Can you show your current code? (HTML, JS and PHP)
The above results seem to be originated by your previous code.
Look, it works fine for me. Do this: open the Web Developer Console which is available in Google Chrome, Chromium and Mozilla Firefox, hit the Network tab and enter a letter in the autocomplete input field, you should see a request to the server, hit the request link and click the Response tab, you should see a JSON object with the rows.
Try with:
$i = 0;
while($row=sqlsrv_fetch_array($select))
{
$data[$i]['code'] = $row['code'];
$data[$i]['desc1'] = $row['desc1'];
$i++;
}
Hi,
check the source of the custom data example in the autocomplete JQueryUI documentation:
The select
property should fit your requirements:
select: function( event, ui ) {
$( "#project" ).val( ui.item.label );
$( "#project-id" ).val( ui.item.value );
$( "#project-description" ).html( ui.item.desc );
$( "#project-icon" ).attr( "src", "images/" + ui.item.icon );
return false;
}
Another example: https://jsfiddle.net/0wdbgage/
Consider also that you could serve Google Fonts from your web server, just download them and set the paths in the CSS file.
-sigh-
Why is it so, that when there's an issue, people look all around :D, but not on the issue.
lol, I asked because I do not know how you are implementing that statement and what you really expect to get. What do you mean by true 404? A redirect to the 404 error page defined by the server?
This:
While Opera fools itself, Firefox doesn't. It shows just super-empty document (not 404, but also not even standard CSS stylesheet). How do I successfully send "404 Not Found" to ALL browser.
is not a useful information, to understand your issue.
Look, to me it's easier to move the includes scripts into a separated directory, then use .htaccess to deny direct access to that directory, so it cannot be accessed through the browser.
This solution does not require to modify the scripts, so nothing like the header()
404 statement, if really needed you could force it through .htaccess and send a more appropriate 403 or even 404.
It's even better if you move the includes directory to the parent of the public_html directory, which if correctly set, is not accessible by the browsers, that way you don't even need to use .htaccess file to define what is accessible and what not.
Hi,
I don't understand your request: defined()
is used only with constants not with statements, are you defining a constant or just trying to include 'somefile.php';
and be sure it's loaded?
Hi,
It happens because of rounding errors, for more information see:
You could try with Decimal()
:
from decimal import Decimal
# with binary floating points
print(divmod(356, 3.56))
(99.0, 3.5599999999999947)
# with arbitrary roundings
print(Decimal('356') % Decimal('3.56'))
0.0
Example: http://ideone.com/a6UDRi
Hi Simon,
I think your issue is given by the configuration of your local Apache server. From what I have understood you are not configuring a VirtualHost for your project. You are simply creating a new directory (folder) into the document root of the default Apache host.
By doing this, you have to tell the rewrite engine to check the correct path before trying to apply the rewrite rules. For example, these will apply to the document root:
# first .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^new/([0-9]+)/?$ new.php?msgID=$1 [L]
</IfModule>
So it will try to rewrite the url starting from //localhost/
, instead, the following will apply to the project folder:
# second .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /WallScript/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^new/([0-9]+)/?$ new.php?msgID=$1 [L]
</IfModule>
So, it will start from //localhost/WallScript/
. It depends on the value assigned to the RewriteBase directive:
RewriteBase /WallScript/
Here an example of the folder structure:
/
├── functions.php
├── .htaccess
├── index.php
├── new.php
└── WallScript
├── .htaccess
└── new.php
To recap: the first .htaccess applies to the /new.php file, i.e. the file placed in the document root, the second applies to the /WallScript/new.php file.
By default Apache inherits the .htaccess rules to the subfolders, so if the configuration allows it, you can avoid to write multiple .htaccess and place just one in the document root.
The R=301
flag that I suggested in my previous posts, was to test which file was …
Hi,
you could use filter_var()
with FILTER_SANITIZE_NUMBER_INT
:
filter_var($not_an_int, FILTER_SANITIZE_NUMBER_INT);
filter_var($actual_int, FILTER_SANITIZE_NUMBER_INT);
Will return string, that can be casted, se an example here:
To tell the truth, there is a space between the substitution and the flags:
RewriteRule ^new/([0-9]+)/?$ new.php?msgID=$1 [R=301,L]
↑ ↑ ↑
space space space
What you returned is without the space. That rule works fine for me, so could you share the code of the new.php file? Because, I really don't have other suggestions right now.
Ok, my mistake :) I forgot to prepend the correct flag, it's R=301
:
RewriteRule ^new/([0-9]+)$ new.php?msgID=$1 [R=301,L]
RewriteRule ^new/([0-9]+)/$ new.php?msgID=$1 [R=301,L]
where R
stands for Redirect:
Ok and what is the error in the Apache error.log? It could be a loop, which could mean a missing rewrite condition, like:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Used to avoid conflicts with existing files and directories. Now can you share the full rewrite rules and the relevant part of the new.php script?
So, if you do:
/new/155/
With an ending slash it matches correctly? If the new.php file is in localhost/
try these:
RewriteRule ^project/new/([0-9]+)$ new.php?msgID=$1 [L,301]
RewriteRule ^project/new/([0-9]+)/$ new.php?msgID=$1 [L,301]
Otherwise, if it's in localhost/project/
and the .htaccess file is in the same path, remove the project token from the rewrite rules. You can test them here:
Consider also to set a RewriteBase to avoid issues with paths, if that is the problem.
the thing is that i call the php fuction in a separate file that doesn't get the $_GET id
$_GET
is a superglobal variable, so it's available in all the scopes of the script, even if you execute a function into an included script. Try $_GET['msgID']
as defined in the rewrite rule.
Ok, so the /155
segment should be the msg_id
, correct? Can you show us the rewrite rules? Maybe you just need to point to another index, try to dump the $_GET array var_dump($_GET);
to see what is set.
If I can suggest, consider to include a router into your application, something like nikic/FastRoute:
This is already in the Slim framework, and allows you to define a new link like this:
$app = new \Slim\App();
$app->get('/messages/{msg_id}/{another_var}', function($request, $response, $args) {
echo $args['msg_id'] . ' ' . $args['another_var'];
});
Adding variables at that point becomes easy.
What are you using to build those links? Mod rewrite or a router? (Slim perhaps?)
If the rewrite rule defines msg_id
then it will be accessible through that link, otherwise you have to append it /project/new/155?msg_id=123
or change the rule.
The backtick is the operator used to define those objects known as identifiers: table names, columns, databases and to distinguish a column name, for example, from a reserved word. See: http://dev.mysql.com/doc/refman/5.7/en/identifiers.html
To test your query, open the mysql client and run:
\W -- to enable warnings
SELECT `type` FROM `messages` WHERE `msg_id` = 1;
If it runs fine, then see if $_GET['msg_id']
is set, because, otherwise, it's like sending this query:
SELECT `type` FROM `messages` WHERE `msg_id` = ;
Which will raise the same syntax error.
Add backticks to type
, as suggested by Pritaeas:
SELECT `type` FROM ...
Hi!
The method/function fetchAll()
of the PDO library returns an array, which is an empty array if no rows are matched, what you want here is probably fetchColumn()
:
$type = $stmt->fetchColumn();
And you also want to use prepared statements: I know I repeat myself a lot on this subject, but it's really important, your current code is exposed to SQL injection, I could delete your entire database from there. Write it correctly also for the other users that will read this forum and take your code as example. Bye!
Hello,
are you aware that the referrer can be spoofed? Simple test:
nc -l 8000
curl --verbose --header --referer http://google.com/ http://localhost:8000/
You'll get:
GET / HTTP/1.1
User-Agent: curl/7.35.0
Host: localhost:8000
Accept: */*
Referer: http://google.com/
More information here: https://en.wikipedia.org/wiki/Referer_spoofing
@Antony try:
SELECT * FROM `TABLENAME` ODER BY date_format(str_to_date(`TIME_COLUMN`, '%r'), '%T') ASC;
This will convert the string to a timestamp that MySQL can parse, then use %T
to get the order in the 24H format. But, as suggested, it's better to convert the existing rows into the 24H format and then always save in that format, to avoid extra processing. So you could run an update query, just like above:
UPDATE `TABLENAME` SET `TIME_COLUM` = date_format(str_to_date(`TIME_COLUMN`, '%r'), '%T');
Replace TABLENAME
and TIME_COLUMN
with yours and remember to test on a copy.
Rule is: save always in UTC, save always in the format that the database can parse, then convert for the client.
For more info see:
Bye!
Hello,
so, standing at the original example you want two rows for each date > item
, correct?
Use implode()
after each cycle, change this:
# loop each date > item
foreach($items as $item)
# loop each date > item > item
foreach($item as $elem)
$r[] = sprintf('%s %s %s'
, $elem->attributes()->Name
, $elem->attributes()->Type
, $elem);
to:
# loop each date > item
foreach($items as $item)
{
# initialize the $r array at each loop
$r = [];
# loop each date > item > item
foreach($item as $elem)
{
$r[] = sprintf('%s %s %s'
, $elem->attributes()->Name
, $elem->attributes()->Type
, $elem);
}
# convert the $r array to a string
$s[] = implode(',', $r);
}
The contents of $s
will look like this:
array (2) [
string (184) "received Date 2015/12/18 00:00,accepted Date 2016/03/31 00:00,aheadofprint Date 2016/04/14 00:00,entrez Date 2016/04/15 06:00,pubmed Date 2016/04/15 06:00,medline Date 2016/04/15 06:00"
string (152) "epublish Date 2016/05/23 00:00,entrez Date 2016/07/12 06:00,pubmed Date 2016/07/12 06:00,medline Date 2016/07/12 06:00,pmc-release Date 2017/01/01 00:00"
]
If you want them all in the same string, then just initialize the $r
array before or the first loop (# loop each <date> node
) and move the implode out of the loops, at the end, basically:
$r = [];
# loops
$s = implode(',', $r);
Wait, was it about the editor?! O_O
I thought it was about PHP, sorry!
If you just need to remove what comes after the first occurrence of the bracket and display what is remaining, then you could basically loop the input into strstr()
, like this:
$line = 'Águila (El Salvador)';
$out = strstr($line, '(', TRUE) . '(';
print $out; # Águila (
See: http://php.net/manual/en/function.strstr.php
Example:
<?php
$fp = function($file) {
$out = '';
$lines = file($file);
foreach($lines as $line)
$out .= strstr($line, '(', TRUE) . '(' . PHP_EOL;
return $out;
};
$output = $fp('./input.txt');
print $output;
Or switch to fopen if the input is a big file.
It happens because you have to manually move to the next node, you can do like this:
<?php
$file = 'dates.xml';
$xml = simplexml_load_file($file);
# loop each <date> node
foreach($xml->date as $node) {
$items = $node->children();
# loop each date > item
foreach($items as $item)
# loop each date > item > item
foreach($item as $elem)
$r[] = sprintf('%s %s %s'
, $elem->attributes()->Name
, $elem->attributes()->Type
, $elem);
}
print_r($r);
Will return:
Array
(
[0] => received Date 2015/12/18 00:00
[1] => accepted Date 2016/03/31 00:00
[2] => aheadofprint Date 2016/04/14 00:00
[3] => entrez Date 2016/04/15 06:00
[4] => pubmed Date 2016/04/15 06:00
[5] => medline Date 2016/04/15 06:00
[6] => epublish Date 2016/05/23 00:00
[7] => entrez Date 2016/07/12 06:00
[8] => pubmed Date 2016/07/12 06:00
[9] => medline Date 2016/07/12 06:00
[10] => pmc-release Date 2017/01/01 00:00
)
To get the attributes, in this case, since $elem
will be a SimpleXMLElement object you can use the attributes()
method:
Use var_dump()
or a debugger like this to see which kind of object you are iterating, for example:
foreach($items as $item)
sd($item);
Returns:
SimpleXMLElement (2) (
public @attributes -> array (2) [
'Name' => string (7) "History"
'Type' => string (4) "List"
]
public Item -> array (6) [
string (16) "2015/12/18 00:00"
string (16) "2016/03/31 00:00"
string (16) "2016/04/14 00:00"
string (16) "2016/04/15 06:00"
string (16) "2016/04/15 06:00"
string (16) "2016/04/15 06:00"
]
)
So you can see the attributes of the main node:
…Hi,
in the first line (drop ...
) is missing the separator (the semi-colon in this case), so all the following falls into a syntax error.
// ops! I just saw your reply Diafol! :D
Hi,
can you share the error with us? Also: are you using MySQLi or PDO? The former returns boolean TRUE for successful inserts, the latter instead will return an object and your IF statement would fail because you're using the identical comparison operator ===
rather than the equal comparison operator ==
.
See:
I try keep it handy: I'm on linux, I've only installed PHP (+ libraries) and the databases, I'm not using Apache or Nginx for development, not if I don't have to deal with their modules, I just use the built-in PHP server which is enough for testing:
Yes and the folder is on Read Only i change it and keeps going back to Read Only state.
Here you may want to change the ownership of the folder to avoid the change, but I'm not sure this won't break WAMP :D so, yes, consider the switch to XAAMP or wait for other suggestions.
You mean the config file of WampServer?
With software I was referring to WampServer, with config file to the php.ini, sorry.
So the file is restored to the original? As I wrote I don't know about WAMP setups, it could be the software that keeps the file in memory, stop the programm, not only the server, edit the config file and start it again. Check also if the file is in read mode and make it writable.
Fix this part of the code:
foreach ($_FILES['audioaud']['name'] as $name => $value)
{
$filename = stripslashes($_FILES['audioaud']['name'][$name]);
the first argument of the foreach should be an array, you're submitting a string, unless you're uploading multiple arrays and you set the name attribute to array, so instead of:
<input type="file" name="audioaud" id="audioaud">
you shall write:
<input type="file" name="audioaud[]" id="audioaud">
only by applying this change you get arrays:
Array
(
[name] => Array
(
[0] => foo.txt
[1] => bar.txt
)
[type] => Array
(
[0] => text/plain
[1] => text/plain
)
...
Otherwise you get strings and the loop is not required. To simplify the testing part, add a debugger, a good choice for SlimPHP is Kint, check it here:
Docs:
Are they more than one php.ini files on a wamp server?
I don't know about WAMP setups, on linux yes: there are different config files for each extension and SAPI, for example when using PHP-FPM you can create separated pools to start an app with a different user & group.
You're welcome. About the first warning see also:
but the audio file still doesnt been uploaded.
Can you show the script?
Hi,
remove the ;
from this line:
always_populate_raw_post_data = -1
semi-colons, in the PHP configuration files, are used to comment lines and exclude them from the parsing.
//Edit
And remember to reload the server.
Ok, then you could use PDO to group the results into an array, the index key is defined by the first column listed in the SELECT statement, in your case it will be the town
column.
Here's an example:
$conn = new PDO('mysql:host=localhost;dbname=my_db', 'username', 'password');
$stmt = $conn->prepare('SELECT `town`, `il`.* FROM `info_list` AS `il` ORDER BY `town`, `name` ASC');
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_OBJ);
Then create a template for the list:
$list = '';
$template = '<li>%s<ul>%s</ul></li>';
And loop the results:
foreach($rows as $town => $value)
{
$li = '';
foreach($value as $row)
$li .= "<li>$row->name, $row->job</li>";
$list .= sprintf($template, $town, $li);
}
Then into your HTML simply do:
<ul>
<?php echo $list; ?>
</ul>
More info here: http://php.net/manual/en/pdostatement.fetchall.php
Hi,
so you want to group the names under each town? For example:
<ul>
<li>Town
<ul>
<li>Name X</li>
<li>Name Y</li>
<li>Name Z</li>
</ul>
</li>
...
</ul>
is this correct?
Date is a reserved word, use backticks for the column and table names.
Hi,
array_diff()
will return the index key, so you can get the corresponding values for each array, as example:
<?php
$a = [4711, 4712, 4713, 4714];
$b = ['ALFA ROMEO', 'BMW', 'SKODA', 'TOYOTA'];
$c = [6.5, 65, 0.2, 2.9];
$d = [4711, 4712, 2856, 4714];
$diff = array_diff($a, $d);
$key = key($diff);
$template = '%s %s %s';
echo sprintf($template, $a[$key], $b[$key], $c[$key]);
Note that if array_diff()
returns more results you will have to loop, as the internal pointer will return only the first index key.