Jump to content

Jurtz

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by Jurtz

  1. So I set the query now before the foreach like that. $connection = mysqli_connect("localhost", "xx", "xx", "xx") or die("Error " . mysqli_error()); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $sql = mysqli_query($connection, "SELECT * FROM mytable"); while($row = mysqli_fetch_array($sql)) { $names[] = $row['firstname']; } Here I need some assistant. where is the mistake. Basically I have both arrays included now. foreach($data2['wow_accounts']['0']['characters'] as $key => $item) { if($row["firstname"] == $item['name'] && row["lastname"] == $item['lastname'] ) { $class_string = ''; } else { $class_string = ' class="my-additional-class"'; } echo '<tr>'; echo '<td>'; echo $item['firstname']; echo '</td>'; echo '<td>'; echo $item['lastname']; echo '</td>'; echo '<td>'; echo '<button class="btnSelect">Select</button>'; echo '</td>'; echo '</tr>'; } echo '</table>'; } }
  2. Yes, firstname and lastname are the only uniquie ones. I improved the query now and played it outside of the foreach loop. But still don´t work. My try: $link = mysqli_connect("localhost", "xxx", "xx", "xx"); $query = "SELECT firstname, lastname FROM mytable"; if ($result = mysqli_query($link, $query)) { while ($row = mysqli_fetch_assoc($result)) { echo '<table class="formatHTML5" id="myTable">'; foreach($data2['wow_accounts']['0']['characters'] as $key => $item) { if($row["firstname"] == $item['name'] && row["lastname"] == $item['lastname'] ) { $class_string = ''; } else { $class_string = ' class="my-additional-class"'; } echo '<tr>'; echo '<td>'; echo $item['firstname']; echo '</td>'; echo '<td>'; echo $item['lastname']; echo '</td>'; echo '<td>'; echo '<button class="btnSelect">Select</button>'; echo '</td>'; echo '</tr>'; } echo '</table>'; } }
  3. Hello, I have the following table which is created out of a foreach loop. The variables are coming from an extern API array. I´ve made a screenshot for better understanding. This the table: foreach($data2['wow_accounts']['0']['characters'] as $key => $item) { echo '<tr>'; echo '<td>'; echo $item['firstname']; echo '</td>'; echo '<td>'; echo $item['lastname']; echo '</td>'; echo '<td>'; echo '<button class="btnSelect">Select</button>'; echo '</td>'; echo '</tr>'; } echo '</table>'; I also have a mysql table with some stored values. I also made a screenshot. I want now, if the php foreach loop finds a match with the mysql column "lastname" this specific row should get the <tr class="my-additional-class">. In this example the first row "Malygos" should have the <tr class="my-additional-class">. I tried the following, but with no success. Could you help me please? foreach($data2['wow_accounts']['0']['characters'] as $key => $item) { $result = mysqli_query("SELECT lastname FROM mytable"); if($result == $item['lastname']) { $class_string = ''; } else { $class_string = ' class="my-additional-class"'; } echo '<tr>'; echo '<td>'; echo $item['firstname']; echo '</td>'; echo '<td>'; echo $item['lastname']; echo '</td>'; echo '<td>'; echo '<button class="btnSelect">Select</button>'; echo '</td>'; echo '</tr>'; } echo '</table>';
×
×
  • 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.