We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Shared many queries in php developer forum | Forum

Topic location: Forum home » Support » General Questions
Mai
Mai Sep 3 '19
Hi all, 

I am a beginner and have been learning various programming languages like PHP, DotNet, Java etc. I faced an issue regarding php programming in which I wanted to learn how we can find out the difference between two or more arrays based upon key and value of arrays.

 I have shared many queries in php developer forum & received fruitful results, so hoping a great support to my query in this community too.

Thanks 

dave Leader
dave Sep 17 '19
You know that Java and Javascript are different correct? 


Here is where i go if i need alittle reminder about PHP stuff... 


 https://www.php.net/manual


There are lots of options to compare arrays, it depends on if you are looking for a specific value  such as  if the word hello is in the array or if you want the key with it or if you want to move the pointer or make a new array with the results or just compare the two.   


This is an easy one but i dont know if it will apply to your needs as you were not specific. 


https://www.php.net/manual/en/function.in-array.php


As you learn and use that site, be sure you look for the warning that if something is depricated or not, it will give you a link to what you need to use instead. 

The Forum post is edited by dave Sep 17 '19
Genest
Genest Apr 22 '22
I would say that marathon training is not that easy for everybody but you can surely try it with bunch of your friends who can help you out as online cheap assignment writing service click resources https://trust-essay.org/ has helped me with my all writing assignment to homework which was too difficult to me to complete anything on time,.
Nicholas Griffith
Nicholas Griffith Aug 28 '22


As you already have your Database Structure and as you already and should probably know in order to link your categories table with your forums table you need to have at least one column in both similar which is a category_id from your categories table auto incremented column namely as id so in order to categorize your forum into the specific category you will need to add the category id to an extra column as category_id in your forums table so each forum will have it's category mentioned in there in id value.

And then you can list your forums by categories like this way as :

Note : This code will check for every forum category and it will sort of list all those forums under each category..!

<?php //Assuming you have fetched whole data from forums table in $forums //And whole data from categories in $categories //So moving forward with the code foreach ($categories as $category) { echo "<h1>".$category['category_title']."</h1>"; $category_id = $category['category_id']; $query = mysqli_query($mysqli,"SELECT * FROM forums WHERE category_id='$category_id'"); $forums = array(); while ($rows = mysqli_fetch_array($query)) { $forums[] = $rows; } foreach ($forums as $forum) { echo "Title :".$forum['forum_title']."</br>"; echo "Descripton :".$forum['forum_description']."</br></br></br>"; } echo "</br></br></br></br>"; } ?>

WORKING CODE EXAMPLE:

<?php $categories = array( array('id' => "04",'category_title' => "News & Support"), array('id' => "23",'category_title' => "Current Affairs"), array('id' => "12",'category_title' => "Politics")); $forums = array( array('forum_title' => "News 1",'category_id' => "04"), array('forum_title' => "News 2",'category_id' => "04"), array('forum_title' => "Current Afairs 1",'category_id' => "23"), array('forum_title' => "Current Afairs 2",'category_id' => "23"), array('forum_title' => "Politics 1",'category_id' => "12"), array('forum_title' => "Politics 2",'category_id' => "12")); foreach ($categories as $category) { echo "<h1>".$category['category_title']."</h1>"; $category_id = $category['id']; $output = array(); for ($i=0;$i<=count($forums);$i++) { if ($category_id == $forums[$i]['category_id']) { $add_forum = array('forum_title' => $forums[$i]['forum_title'],'category_id' => $forums[$i]['category_id']); array_push($output, $add_forum); } } for ($i=0;$i<=count($output);$i++) { echo "Title :".$output[$i]['forum_title']."</br>"; } echo "</br></br></br></br>"; } ?>