Jump to content

Zorglub

Members
  • Posts

    15
  • Joined

  • Last visited

Everything posted by Zorglub

  1. I want to get the latest 3 cars viewed. In the to I save the view in til MYSQL and in the code above I read the data I get from saving the vehicleid, the timestamp and the img in the table latest.
  2. I mean it would be relevant, but I have only registered the cars being visited. Not by whom.
  3. // Testing if exists if($row['vehicleid'] = $vehicle->VehicleId) { $rowcount=mysqli_num_rows($result); echo "Timestamp: " . $row['timestamp'] . "<br>"; echo "VehicleId: " . $row['vehicleid'] . "<br>"; echo "img: " . $row['img'] . "<br>"; } The url example: https://i.ebayimg.com/images/g/FQ0AAOSw8WdbfU5w/s-l1600.jpg
  4. $temp .= "<img class='cc-images' src='" . $vehicle->Pictures[$p] . "'>"; It's from a JSON file... the URL of the IMG...
  5. Hi, I am trying to make a latest visited cars segment where I save the image and id of the car the the user sees. But I am lost as how to go from here... // DATABASE CONNECTION ///////////////////////////////////// $servername = "localhost"; $username = "root"; $password = "Wichmand14"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $imgUrl = $vehicle->Pictures[1]; $getTimeStamp = "SELECT * FROM latest"; $result = $conn->query($getTimeStamp); $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$imgUrl')"; if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { if($row['vehicleid'] <> $vehicle->VehicleId) { echo "Timestamp: " . $row['timestamp'] . "<br>"; echo "VehicleId: " . $row['vehicleid'] . "<br>"; } } } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); /////////////////////////////////////////////////////////
  6. Hi, I am trying to make a latest visited cars segment where I save the image and id of the car the the user sees. But I am lost as how to go from here... $servername = "localhost"; $username = "root"; $password = "Wichmand14"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $imgUrl = $vehicle->Pictures[1]; $getTimeStamp = "SELECT timestamp FROM latest"; $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$imgUrl')"; if ($getTimeStamp->num_rows > 0) { // output data of each row while($row = $getTimeStamp->fetch_assoc()) { echo "Timestamp: " . $row['timestamp']; } } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close();
  7. I found the solution... To make the picture a variable: $imgUrl = $vehicle->Pictures[1]; $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$imgUrl')";
  8. The array contains url's to the images, so I do not need to upload any images... The data is a JSON url... The whole code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Look at car</title> <link rel="stylesheet" href="./css/style-show-room.css"> </head> <body> <div class="container"> <?php $id = $_GET['VehicleId']; $url = 'https://gw.bilinfo.net/listingapi/api/export'; // provide your username and password here $auth = base64_encode("demo:ocfB6XzF73"); // create HTTP context with basic auth $context = stream_context_create([ 'http' => ['header' => "Authorization: Basic $auth"] ]); // query for data $data = file_get_contents($url, false, $context); // $escaped = json_encode($data); $escaped = json_decode($data); //, JSON_FORCE_OBJECT /*Initializing temp variable to design table dynamically*/ $temp = "<table class='car-list'>"; /*Defining table Column headers depending upon JSON records*/ /*Dynamically generating rows & columns*/ foreach ($escaped->Vehicles as $vehicle) { if($vehicle->VehicleId == $id) { // DATABASE CONNECTION ///////////////////////////////////// $servername = "localhost"; $username = "root"; $password = "Wichmand14"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$vehicle->Pictures[0]')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ///////////////////////////////////////////////////////// // INSERT VIEWED CAR - END $temp .= "<tr>"; $temp .= "<th colspan='4' class='th-style'>" . $vehicle->Make . " " . $vehicle->Model . " " . $vehicle->Variant . "</th>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td colspan='4' class='td-style'>"; for ($p = 0; $p < $vehicle->PictureCount; $p++) { if ($p < 1) { $temp .= "<table class='images-table'>"; $temp .= "<tr>"; $temp .= "<td rowspan='2' class='td-style'>"; $temp .= "<img class='cc-images' src='" . $vehicle->Pictures[$p] . "'>"; $temp .= "</td>"; $temp .= "</tr>"; $temp .= "</table>"; } } $temp .= "</td>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td class='td-style'>Producent: " . $vehicle->Make . "</td>"; $temp .= "<td class='td-style'>Model: " . $vehicle->Model . "</td>"; $temp .= "<td class='td-style'>Variant: " . $vehicle->Variant . "</td>"; $temp .= "<td class='td-style'>Sælger: " . $vehicle->DealerName . "</td>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td class='td-style'>Pris: " . $vehicle->Price . "</td>"; $temp .= "<td class='td-style'>Type: " . $vehicle->PriceType . "</td>"; $temp .= "<td class='td-style'>Kontaktpris: " . $vehicle->CashPrice . "</td>"; $temp .= "<td class='td-style'>Udsalgspris: " . $vehicle->WholesalePrice . "</td>"; $temp .= "</tr>"; $temp .= "<tr>"; $temp .= "<td colspan='4' class='td-style'>Bil id: " . $vehicle->VehicleId . "</td>"; $temp .= "</tr>"; } } // START $servername2 = "localhost"; $username2 = "root"; $password2 = "Wichmand14"; $dbname2 = "visited"; // Create connection $conn2 = new mysqli($servername2, $username2, $password2, $dbname2); // Check connection if ($conn2->connect_error) { die("Connection failed: " . $conn2->connect_error); } $sql2 = "SELECT * FROM latest LIMIT 3"; $result2 = $conn2->query($sql2); if ($result2->num_rows > 0) { // output data of each row while($row = $result2->fetch_assoc()) { for ($i = 0; $i < 3; $i++) { if ($i < 3) { $temp .= "<tr>"; $temp .= "<td colspan='2'>"; $temp .= "<img class='latest-img' src='" . $row["img"] . "'>"; $temp .= "" . $row["img"] . ""; $temp .= "</td>"; $temp .= "<td colspan='2'>" . $row["vehicleid"]. "</td>"; $temp .= "</tr>"; } } } } else { echo "0 results"; } $conn2->close(); // END /*End tag of table*/ $temp .= "</table>"; /*Printing temp variable which holds table*/ echo $temp; // echo $data; ?> </div> </body> </html>
  9. Hi Now I don't mean saving the whole array, only number, say 3. How would you do that? My code so far: // DATABASE CONNECTION ///////////////////////////////////// $servername = "localhost"; $username = "root"; $password = "Fun"; $dbname = "visited"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $dateValue = date('d-m-Y H:i:s'); $sql = "INSERT INTO latest (timestamp, vehicleid, img) VALUES ('$dateValue', '$vehicle->VehicleId', '$vehicle->Pictures[0]')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ///////////////////////////////////////////////////////// But it only inserts "Array()" into to the MYSQL...
  10. My try so far...: I want to get the data, then set all the cars up in a list (<li></li>) so I can style it later. <?php //The URL of the resource that is protected by Basic HTTP Authentication. $url = 'https://gw.bilinfo.net/listingapi/api/export'; //Your username. $username = 'demo'; //Your password. $password = 'ocfB6XzF73'; //Initiate cURL. $ch = curl_init($url); //Specify the username and password using the CURLOPT_USERPWD option. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); //Tell cURL to return the output as a string instead //of dumping it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Execute the cURL request. $response = curl_exec($ch); $jsonDecode = json_decode($url, true); echo "<b>Bil:</b> " . $jsonDecode['Vehicles']['Pictures']; //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } //Print out the response. echo $response; ?>
  11. This example just takes the $response, and put it all in there. I need to control the individual cars so I can style them...
  12. This a example without authentication: <?php $jsonurl = "https://reqres.in/api/users/2"; $json = file_get_contents($jsonurl); $jsonDecode = json_decode($json, true); echo "<b>E-mail:</b> " . $jsonDecode['data']['email']; echo $jsonDecode['data']['first_name']; ?>
  13. The goal is to mark up with html Take at look at the output, it is a cluster, but I want to mark up with HTML: "<td>" . name->model . "<td>"
  14. I have this code: <?php //The URL of the resource that is protected by Basic HTTP Authentication. $url = 'https://gw.bilinfo.net/listingapi/api/export'; //Your username. $username = 'demo'; //Your password. $password = 'ocfB6XzF73'; //Initiate cURL. $ch = curl_init($url); //Specify the username and password using the CURLOPT_USERPWD option. curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); //Tell cURL to return the output as a string instead //of dumping it to the browser. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Execute the cURL request. $response = curl_exec($ch); //Check for errors. if(curl_errno($ch)){ //If an error occured, throw an Exception. throw new Exception(curl_error($ch)); } //Print out the response. echo $response; ?> But how do I put it into HTML though?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.