This is my first time using SQL, I'm using PHPMyAdmin. My connection to the database works fine.
I have 8 database tables, but I'm currently just trying to display the data from 5 of them. This is my ER model. I want to display city, place, photo and cat tables in an RSS feed.
Currently when load up the XML it repeats some of the entries, for example for each place it repeats the city information. So for place 1 it shows all the city data, then the place data, and the same for place 2 ect.This is what the first few entries for the current output looks like, it's a long XML file due to the repeats.
I want the city information to be displayed once, then the corresponding place data to be displayed after. So City 1, then place 1,2,3,4,5,6 (as they correspond to city 1), then City 2, then place 7,8,9,10 (as they correspond to city 2).
This is what my current select query looks like :
SELECT s.city_id, s.city_name, s.country_name, s.population,
s.city_long, s.city_lat, s.woeid, s.currency, s.region,
s.time_zone, s.area, s.postal_code, n.place_name, n.capacity,
n.place_long, n.place_lat, n.city_id, c.place_id, c.category_id,
ss.category_id, ss.category_name, ss.category_icon, cc.photo_id,
cc.place_id, cc.photo_name
FROM city s
JOIN place n ON s.city_id = n.city_id
JOIN place_cat c ON c.place_id = n.place_id
JOIN cat ss ON ss.category_id = c.category_id
JOIN photo cc ON cc.place_id = n.place_id
I don't know if it's an issue with the query or with the way I'm echoing the data. This is how I'm echoing it :
foreach($results as $result)
{
//
echo '<item>'. PHP_EOL;
echo '<city>'. PHP_EOL;
echo '<CityName>' . $result['city_name'] . '</CityName>'. PHP_EOL;
echo '<CountryName>' . $result['country_name'] . '</CountryName>'. PHP_EOL;
echo '<Population>' . $result['population'] . '</Population>'. PHP_EOL;
echo '<CityLat>' . $result['city_lat'] . '</CityLat>'. PHP_EOL;
echo '<CityLong>' . $result['city_long'] . '</CityLong>'. PHP_EOL;
echo '<Woeid>' . $result['woeid'] . '</Woeid>'. PHP_EOL;
echo '<Currency>' . $result['currency'] . '</Currency>'. PHP_EOL;
echo '<Region>' . $result['region'] . '</Region>'. PHP_EOL;
echo '<TimeZone>' . $result['time_zone'] . '</TimeZone>'. PHP_EOL;
echo '<Area>' . $result['area'] . '</Area>'. PHP_EOL;
echo '<PostalCode>' . $result['postal_code'] . '</PostalCode>'. PHP_EOL;
echo '<place>'. PHP_EOL;
echo '<PlaceName>' . $result['place_name'] . '</PlaceName>'. PHP_EOL;
echo '<Capacity>' . $result['capacity'] . '</Capacity>'. PHP_EOL;
echo '<PlaceLat>' . $result['place_lat'] . '</PlaceLat>'. PHP_EOL;
echo '<PlaceLong>' . $result['place_long'] . '</PlaceLong>'. PHP_EOL;
echo '<Category>' . $result['category_name'] . '</Category>'. PHP_EOL;
echo '<Photo>' . $result['photo_name'] . '</Photo>'. PHP_EOL;
echo '</place>'. PHP_EOL;
echo '</city>'. PHP_EOL;
echo '</item>'. PHP_EOL;
}
Is there a way to display the data the way I want to (city information to be displayed once, then the corresponding place data to be displayed after)? If so how?
I'm trying to create a page that displays content from database when specific title is selected, and all the comments added to it (only comments for the selected title should be visible) by other users. I want make the id and review_id to work together on the same line. I cant create two separate echo's as it creates two separate titles.
I've tried to link the values together but cant make it work.
echo '<li>' . $comment['name'] . ' - ' . $comment['date'] . '</li>';
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
echo '<li>' . $comment['name'] . ' - ' . $comment['date'] . '</li>';
Is there a way to make "id" and "review_id" work at the same line ?
I have made a chatroom with php and I would like to be able to add the ability to comment on a post, and to do this, I need to be able to find out a the number after a phrase in php.
The phrase will always be "this is post number: " but the number changes based on what post number the post you are looking at is.
The website is linked here
Below, I have the code that inserts the formatted user input into a .txt file:
//increases the post number by 1
$post_num = file_get_contents("post_num.txt");
$post_num ++;
file_put_contents("post_num.txt", $post_num);
//writes message to file
file_put_contents('posts.txt', "<div class='post'><div class='title'><b>" . $title . "</b></div>" . $postimg . "<div class='message'>" . showBBcodes($message) . "</div><div class='footer'>Posted By: " . $username . "<br> This is post number: " . $post_num . "</div><form action='finish_comment.php' method='post'><input placeholder='comment' name='comment'><input type='submit' value='comment'></form></div><br> \n", FILE_APPEND);
//redirects the user back to posts.php
echo "<script>location.href = 'posts.php'</script>";
The phrase with the post number is in the piece of code that reads:
<div class='footer'>Posted By: " . $username . "<br> This is post number: " . $post_num . "</div>
When I retrieve a blob via PHP it only loads about half the image.
Here's my code:
<?php
require 'dbconnect.php';
$q="SELECT * FROM mtgcards WHERE Name LIKE '%".$_POST['search']."%'";
$r = mysqli_query($dbc, $q);
while ($row = mysqli_fetch_array($r)) {
echo '<br>'. 'Name: ' . $row['Name'] . ' Mana cost: ' . $row['Mana Cost'] . ' Colour: ' . $row['Colour'] . ' Set: ' . $row['Set'] . ' Ability: ' . $row['Ability']. '<img src="data:image/jpeg;base64,' . base64_encode($row['Image']) . '" width="223" height="311">';
}
mysqli_close($dbc);
?>
Here's what the full picture is and what the picture when I retrieve it comes out as.
Thanks in advance!
As it seems and was determined in comments, BLOB is too small a column type for the image's (raw) size, therefore you will need to use LONGBLOB.
Reference:
http://dev.mysql.com/doc/refman/5.7/en/blob.html
So you will need to alter your column, and resave your data then start over.
Problem:
I am using Google Map API using the link: http://www.phpinsider.com/php/code/GoogleMapAPI/ - and when I try to print out an address on the map manually it will show up but not when selected from a database.
PHP code (this works):
$map->addMarkerByAddress('114 53 Grevgatan 31','The Tudor Arms','<b>The Tudor Arms</b>');
PHP code (this does NOT work):
$location = $row['postalnumber'] . ' ' . $row['address'] . ' ' . $row['city'];
$map->addMarkerByAddress($location , $row['name'],'<b>'. $row['name'] .'</b>');
Desired solution:
To be able to extract data from a table in an SQL database and send it to the Google Map API function.
Additional remarks: When I echo the variables above the address and all information will print out but not when sent to the Google Map API function. Do I need to convert the data into a string?
Yes, you should say google the format like:
$location = $row['postalnumber'] . ' ' . $row['address'] . ' ' . $row['city'];
$map->addMarkerByAddress("'".$location."'", "'".$row['name']."'","'<b>". $row['name'] ."</b>'");